lookahead

Does the Peg.js engine backstep after a lookahead like regexs do?

邮差的信 提交于 2019-12-25 00:46:58
问题 According to regular-expressions.info on lookarounds, the engine backsteps after a lookahead: Let's take one more look inside, to make sure you understand the implications of the lookahead. Let's apply q(?=u)i to quit. The lookahead is now positive and is followed by another token. Again, q matches q and u matches u. Again, the match from the lookahead must be discarded, so the engine steps back from i in the string to u. The lookahead was successful, so the engine continues with i. But i

lookahead in kate for patterns

删除回忆录丶 提交于 2019-12-21 22:54:23
问题 I'm working on compiling a table of cases for a legal book. I've converted it to HTML so I can use the tags for search and replace operations, and I'm currently working in Kate. The text refers to the names of cases and the citations for the cases are in the footnotes, e.g. <i>Smith v Jones</i>127 ......... [other stuff including newline characters].......</br>127 (1937) 173 ER 406; I've been able to get lookahead working in Kate, using: <i>.*</i>([0-9]{1,4}) .+<br/>\1 .*<br/> ...but I've run

Regular Expression - Match all but first letter in each word in sentence

非 Y 不嫁゛ 提交于 2019-12-21 20:03:36
问题 I've almost got the answer here, but I'm missing something and I hope someone here can help me out. I need a regular expression that will match all but the first letter in each word in a sentence. Then I need to replace the matched letters with the correct number of asterisks. For example, if I have the following sentence: There is an enormous apple tree in my backyard. I need to get this result: T**** i* a* e******* a**** t*** i* m* b*******. I have managed to come up with an expression that

How to write a regex lookahead/lookbehind in mysql

僤鯓⒐⒋嵵緔 提交于 2019-12-21 13:32:13
问题 I'm trying to do something like SELECT * FROM table WHERE column REGEXP (abc)(?=def) and I got the error Got error 'repetition-operator operand invalid' from regexp due to the '?' -> see #1139 - Got error 'repetition-operator operand invalid' from regexp Is there an equivalent in mysql that I don't see in https://dev.mysql.com/doc/refman/5.7/en/regexp.html ? or maybe another mysql function that I don't know yet? 回答1: MySQL REGEXP does not support lookaheads, but you can try to achieve the

Regular expression: matching words between white space

妖精的绣舞 提交于 2019-12-19 07:10:45
问题 Im trying to do something fairly simple with regular expression in python... thats what i thought at least. What i want to do is matching words from a string if its preceded and followed by a whitespace. If its at the beginning of the string there is no whitespace required before - if its at the end, dont't search for whitespace either. Example: "WordA WordB WordC-WordD WordE" I want to match WordA WordB WordE . I only came up with overcomplicated way of doing this... (?<=(?<=^)|(?<=\s))\w+(?

REGEX - Matching any character which repeats n times

南笙酒味 提交于 2019-12-18 14:47:05
问题 How to match any character which repeats n times? Example: for input: abcdbcdcdd for n=1: .......... for n=2: ......... for n=3: .. ..... for n=4: . . .. for n=5: no matches After several hours my best is this expression (\w)(?=(?:.*\1){n-1,}) //where n is variable which uses lookahead. However the problem with this expression is this: for input: abcdbcdcdd for n=1 .......... for n=2 ... .. . for n=3 .. . for n=4 . for n=5 no matches As you can see, when lookahead matches for a character, let

REGEX - Matching any character which repeats n times

烈酒焚心 提交于 2019-12-18 14:47:00
问题 How to match any character which repeats n times? Example: for input: abcdbcdcdd for n=1: .......... for n=2: ......... for n=3: .. ..... for n=4: . . .. for n=5: no matches After several hours my best is this expression (\w)(?=(?:.*\1){n-1,}) //where n is variable which uses lookahead. However the problem with this expression is this: for input: abcdbcdcdd for n=1 .......... for n=2 ... .. . for n=3 .. . for n=4 . for n=5 no matches As you can see, when lookahead matches for a character, let

negative lookahead assertion not working in python

故事扮演 提交于 2019-12-18 03:41:45
问题 Task: - given: a list of images filenames - todo: create a new list with filenames not containing the word "thumb" - i.e. only target the non-thumbnail images (with PIL - Python Imaging Library). I've tried r".*(?!thumb).*" but it failed. I've found the solution (here on stackoverflow) to prepend a ^ to the regex and to put the .* into the negative lookahead: r"^(?!.*thumb).*" and this now works. The thing is, I would like to understand why my first solution did not work but I don't. Since

negative lookahead assertion not working in python

旧城冷巷雨未停 提交于 2019-12-18 03:41:03
问题 Task: - given: a list of images filenames - todo: create a new list with filenames not containing the word "thumb" - i.e. only target the non-thumbnail images (with PIL - Python Imaging Library). I've tried r".*(?!thumb).*" but it failed. I've found the solution (here on stackoverflow) to prepend a ^ to the regex and to put the .* into the negative lookahead: r"^(?!.*thumb).*" and this now works. The thing is, I would like to understand why my first solution did not work but I don't. Since

Change Password Control RegEx validating oddly in IE 7 only

我们两清 提交于 2019-12-17 17:08:08
问题 I'm using the Asp.net change password control in my application and all seems to be find and dandy until a user tells me she has a problem meeting the strength requirements when changing her password. Looking into this, she is using IE 7 and no matter what she puts in, the validation fails (and ONLY in IE 7. Firefox, IE 8, Chrome etc. all work as expected). Here is the regex i'm using: ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{5,15}$ I've tried out a few others that I've found throughout this