regex-lookarounds

Optional character in Regex lookbehind (JS)

巧了我就是萌 提交于 2020-08-20 12:15:07
问题 I'm trying to use Regex to parse some content from a template. There are opening tags, and closing tags, but I just want to select the content between these tags (so that I can String.replace) The content looks something like this: OpenTag The Content I want CloseTag OpenTag The Content I want CloseTag and the regex I'm using looks like this: /(?<=OpenTag(\n))(.*?)(?=CloseTag)/msg The problem I'm having is that sometimes there might be a newline, and other times not, but as soon as I make the

Regex: delete between brackets, but only if below character length

谁说胖子不能爱 提交于 2020-07-03 10:05:14
问题 I have strings such as: this is a text ( with parts in brackets ) . This is another string ( with a very long string between brackets that should not be removed because it is too long being over 100 characters ) Desired output: this is a text . This is another string ( with a very long string between brackets that should not be removed because it is too long being over 100 characters ) I can match the bracket content with (with the goal to replace it with an empty string to remove it). \s\(.+

Regex: Capture a word between two words

别等时光非礼了梦想. 提交于 2020-06-29 03:41:21
问题 Let's say these are my inputs: type Database xyz{ abc } type Database { abc } I want to capture just this in both the cases Database The pattern is: "type" + any number of spaces + what i want + any number of spaces + any characters I've this so far but I'm not sure how to match any character in look ahead. (?<=type)\s+(.*)(?=) 回答1: I'm sure you don't need a lookbehind, because just matching and capturing the second word should work: String input = "type Database xyz{ abc }"; Pattern pattern

Regex: Capture a word between two words

大憨熊 提交于 2020-06-29 03:41:01
问题 Let's say these are my inputs: type Database xyz{ abc } type Database { abc } I want to capture just this in both the cases Database The pattern is: "type" + any number of spaces + what i want + any number of spaces + any characters I've this so far but I'm not sure how to match any character in look ahead. (?<=type)\s+(.*)(?=) 回答1: I'm sure you don't need a lookbehind, because just matching and capturing the second word should work: String input = "type Database xyz{ abc }"; Pattern pattern

Python regex lookbehind and lookahead

穿精又带淫゛_ 提交于 2020-05-26 02:44:08
问题 I need to match the string "foo" from a string with this format: string = "/foo/boo/poo" I tied this code: poo = "poo" foo = re.match('.*(?=/' + re.escape(poo) + ')', string).group(0) and it gives me /foo/boo as the content of the variable foo (instead of just foo/boo ). I tried this code: poo = "poo" foo = re.match('(?=/).*(?=/' + re.escape(poo) + ')', string).group(0) and I'm getting the same output ( /foo/boo instead of foo/boo ). How can I match only the foo/boo part? 回答1: Hey try the

Oracle db: How to add spaces in specific positions in strings

萝らか妹 提交于 2020-05-23 10:22:43
问题 Suppose I have a string (varchar2) and I want to add a space wherever I have two consecutive a's. So for example: 'graanh' -> 'gra anh' . OK, this is trivial to do, either with replace or regexp_replace . But both choke on three or more consecutive a's. For example: SQL> select replace('aaaaa', 'aa', 'a a') from dual; REPLACE ------- a aa aa SQL> select regexp_replace('aaaaa', 'aa', 'a a') from dual; REGEXP_ ------- a aa aa This is because the search for the "next" occurrence of the match

How to make a regex for files ending in .php?

两盒软妹~` 提交于 2020-04-05 06:20:54
问题 I'm trying to write a very simple regular expression that matches any file name that doesn't end in .php. I came up with the following... (.*?)(?!\.php)$ ...however this matches all filenames. If someone could point me in the right direction I'd be very grateful. 回答1: Almost: .*(?!\.php)....$ The last four dots make sure that there is something to look ahead at , when the look-ahead is checked. The outer parentheses are unnecessary since you are interested in the entire match. The reluctant .

How to make a regex for files ending in .php?

落花浮王杯 提交于 2020-04-05 06:20:22
问题 I'm trying to write a very simple regular expression that matches any file name that doesn't end in .php. I came up with the following... (.*?)(?!\.php)$ ...however this matches all filenames. If someone could point me in the right direction I'd be very grateful. 回答1: Almost: .*(?!\.php)....$ The last four dots make sure that there is something to look ahead at , when the look-ahead is checked. The outer parentheses are unnecessary since you are interested in the entire match. The reluctant .