regex

Regex to match a word or a dot between words (optionally) in a string

元气小坏坏 提交于 2021-02-10 14:40:42
问题 I'm currently working on an issue that matches a word between special characters. Optionally matches words in between dot. I currently tried below regex pattern it works fairly well in words that have dot in between but I struggled to make it work with word without dot. [^\W\s]+\.+[^\s\W)]+ Given the string: ,DECODE(T3.ATEST,' ',T3.BATEST ,DECODE(NVL(T4.BATEST,'9') ,'1',NVL(T4.BATEST,' ') ,T3.BATEST)) it matches the following: T3.ATEST T3.BATEST T4.BATEST T4.BATEST T3.BATEST Now trying this

Troubles with encoding, pattern matching and noisy texts in R

谁说胖子不能爱 提交于 2021-02-10 14:36:56
问题 We are experiencing problems with encoding, pattern matching using texts automatically downloaded from the web. We need some help to understand where the problem lies and how to fix it. Personally, I must confess that after having read so many posts on the topic, I am completely confused :-) Our texts sometimes include: 1) disturbing Unicode (I have read this already (Automatically escape unicode characters ), but I am not sure in which way it can help with regular expressions) 2) weird

What is regexp_replace equivalent in SQL Server

余生颓废 提交于 2021-02-10 14:18:41
问题 I have this piece of code in Oracle which I need to convert into SQL Server to get the same behavior. I have used the REPLACE function. It seems to be working but I just wanted to make sure. REGEXP_REPLACE( phonenumber, '([[:digit:]]{3})([[:digit:]]{3})([[:digit:]]{4})', '(\1)\2-\3' ) phonenumber 回答1: SQL Server does not have native regex support. You would need to use CLR (or as @Lukasz Szozda points out in the comments one of the newer Language Extensions) . If I have understood the regex

Lua: How do I replace two or more repeating “?” characters with an empty string?

守給你的承諾、 提交于 2021-02-10 14:17:47
问题 I've tried something like the following: local str = "???" string.gsub(str, "(??)*", "") but it removes all '?' characters. I'd like single '?' not replaced but more than one '?' replaced with an empty string. Eg: "?" = not replaced "??" = replaced "???" = replaced Any help would be greatly appreciated. 回答1: Question marks are magic in Lua patterns: they mean 0 or 1 occurrence of the previous class. Lua escapes magic characters in patterns with the % character. The correct pattern for your

Split CLOB column based on new line - Oracle SQL

余生长醉 提交于 2021-02-10 14:16:42
问题 I have a table table1 f_name f_content test1.txt YL*1**50*1~ RX*1~ LR*2~ test2.txt YL*1**49*1~ EE*1~ WW*2~ f_content is CLOB f_name is varchar2 (4000) I have written this SQL: SELECT d.*, c.line_num, translate(substr(d.f_content, part1 + 1, part2 - part1), ' ~' || CHR(10) || CHR(13), ' ') line FROM table1 d CROSS JOIN LATERAL ( SELECT level line_num, DECODE(level, 1, 0, regexp_instr(d.f_content, '~', 1, level - 1)) part1, DECODE(regexp_instr(d.f_content, '~', 1, level), 0, length(d.f_content)

Split CLOB column based on new line - Oracle SQL

你离开我真会死。 提交于 2021-02-10 14:15:25
问题 I have a table table1 f_name f_content test1.txt YL*1**50*1~ RX*1~ LR*2~ test2.txt YL*1**49*1~ EE*1~ WW*2~ f_content is CLOB f_name is varchar2 (4000) I have written this SQL: SELECT d.*, c.line_num, translate(substr(d.f_content, part1 + 1, part2 - part1), ' ~' || CHR(10) || CHR(13), ' ') line FROM table1 d CROSS JOIN LATERAL ( SELECT level line_num, DECODE(level, 1, 0, regexp_instr(d.f_content, '~', 1, level - 1)) part1, DECODE(regexp_instr(d.f_content, '~', 1, level), 0, length(d.f_content)

How to use RegEx in an if statement in Python?

南笙酒味 提交于 2021-02-10 14:15:08
问题 I'm doing something like "Syntax Analyzer" with Kivy , using re (regular expresions). I only want to check a valid syntax for basic operations (like +|-|*|/|(|)). The user tape the string (with keyboard) and I validate it with regex. But I don't know how to use regex in an if statement. That I want is: If the string that user brings me isn't correct (or doesn't check with regex) print something like "inavlid string" and if is correct print "Valid string". I've tried with: if re.match(patron,

Extract PHP Code with Regular Expressions

空扰寡人 提交于 2021-02-10 13:26:10
问题 I want extract the entire PHP Code of this section with Regular Expressions: <h1>Extract the PHP Code</h1> <?php echo(date("F j, Y, g:i a") . ' and a stumbling block: ?>'); /* Another stumbling block ?> */ echo(' that works.'); ?> <p>Some HTML text ...</p> Unfortunately, my Regular Expression got stuck on the stumbling block: /<[?]php[^?>]*[?]>/gim Does someone have a hint how to capture the full PHP Code? 回答1: Something like this might work /<\?php.+?\?>$/ms This pattern uses two flags m for

Setting a relevant expression match to false in a do…while

╄→гoц情女王★ 提交于 2021-02-10 13:21:46
问题 I'm trying to write some very basic code, but I'm also challenging myself on regular expression. I've been able to muddle through the code up to a point, but where I'm really having a problem is that I'm trying to run a do...while loop while the expression is false. At this point in time I get absolutely no errors, but the do...while loop keeps running. I'm attaching the relevant code below, here's hoping it helps. Thank you in advance if (tollResponse == "yes") { Console.WriteLine("How much

iOS - regex to match word boundary, including underscore

浪子不回头ぞ 提交于 2021-02-10 13:16:17
问题 I have a regex that I'm trying to run to match a variety of search terms. For example: the search "old" should match: -> age_old -> old_age but not -> bold - as it's not at the start of the word To do this, I was using a word boundary. However, word boundary doesn't take into account underscores. As mentioned here, there are work arounds available in other languages. Unfortunately, with NSRegularExpression, this doesn't look possible. Is there any other way to get a word boundary to work? Or