negative-lookahead

Is there a way to do negative lookahead in vim regex?

点点圈 提交于 2020-03-17 04:45:50
问题 In Vim, is there a way to search for lines that match say abc but do not also contain xyz later on the line? So the following lines would match: The abc is the best The first three letters are abc and the following would not match: The abc is the best but xyz is cheaper The first three letters are abc and the last are xyz I know about syntax like the following: /abc\(xyz\)\@! but that only avoids matching abcxyz and not if there is anything in between, such as abc-xyz . Using /abc.*\(xyz\)\@!

Bash double bracket regex comparison using negative lookahead error return 2

怎甘沉沦 提交于 2020-01-24 18:51:30
问题 On Bash 4.1 machine, I'm trying to use " double bracket " [[ expression ]] to do REGEX comparison using " NEGATIVE LOOKAHEAD ". I did " set +H " to disable BASH variable' ! ' expansion to command history search. I want to match to " any string " except " arm-trusted-firmware ". set +H if [[ alsa =~ ^(?!arm-trusted-firmware).* ]]; then echo MATCH; else echo "NOT MATCH"; fi I expect this to print "MATCH" back, but it prints "NOT MATCH". After looking into the return code of "double bracket", it

Javascript regex: find a word NOT followed by space character

南笙酒味 提交于 2020-01-14 19:17:27
问题 I need javascript regex that will match words that are NOT followed by space character and has @ before, like this: @bug - finds "@bug", because no space afer it @bug and me - finds nothing because there is space after "@bug" @bug and @another - finds "@another" only @bug and @another and something - finds nothing because both words are followed by space. Help? Added: string is fetched from and FF puts it's own tags at end of it. Although I basically need only the last word starting with @, $

Javascript regex: find a word NOT followed by space character

可紊 提交于 2020-01-14 19:16:31
问题 I need javascript regex that will match words that are NOT followed by space character and has @ before, like this: @bug - finds "@bug", because no space afer it @bug and me - finds nothing because there is space after "@bug" @bug and @another - finds "@another" only @bug and @another and something - finds nothing because both words are followed by space. Help? Added: string is fetched from and FF puts it's own tags at end of it. Although I basically need only the last word starting with @, $

Javascript regex: find a word NOT followed by space character

时光毁灭记忆、已成空白 提交于 2020-01-14 19:16:06
问题 I need javascript regex that will match words that are NOT followed by space character and has @ before, like this: @bug - finds "@bug", because no space afer it @bug and me - finds nothing because there is space after "@bug" @bug and @another - finds "@another" only @bug and @another and something - finds nothing because both words are followed by space. Help? Added: string is fetched from and FF puts it's own tags at end of it. Although I basically need only the last word starting with @, $

Negative look ahead python regex

旧巷老猫 提交于 2020-01-12 04:54:06
问题 I would like to regex match a sequence of bytes when the string '02 d0' does not occur at a specific position in the string. The position where this string of two bytes cannot occur are byte positions 6 and 7 starting with the 0th byte on the right hand side. This is what I have been using for testing: #!/usr/bin/python import re p0 = re.compile('^24 [\da-f]{2} 03 (01|03) [\da-f]{2} [\da-f]{2} [\da-f]{2} (([^0])| (0[^2])|(02 [^d])|(02 d[^0])) 01 c2 [\da-f]{2} [\da-f]{2} [\da-f]{2} 23') p1 =

Variable-Width Lookbehind Issue in Python

点点圈 提交于 2020-01-11 01:26:28
问题 I got the following scenarios: 1) car on the right shoulder 2) car on the left shoulder 3) car on the shoulder I want to match "shoulder" when left|right is not present. So only 3) return "shoulder" re.compile(r'(?<!right|right\s*)shoulder') sre_constants.error: look-behind requires fixed-width pattern It seems like I can't use \s* and "|" How can I solve this. Thanks in advance! 回答1: regex module: variable-width lookbehind In addition to the answer by HamZa, for any regex of any complexity

Regex for significant figures of a defined size (any language)

柔情痞子 提交于 2019-12-24 21:05:28
问题 I would have thought this would be fairly common, but haven't found a solution What I would like is a regular expression that fails on a set number of significant figures (a Max), but passes for less than the Max. I would like it to work with both dot or comma (french) decimal separators. So for 15 significant figures, these should pass: 0 0.00 1 -1 1.23456789012345 10.2345678901234 12.3456789012345 -123.4 -12.34 -1,33 -1.33 -123456789012345 -1234567890123450 -12345678901234.50 12345678901234

Getting last match from multiple matches

半世苍凉 提交于 2019-12-24 08:46:33
问题 I am trying to match and get the last occurrence of a pattern in my file using notepad++. My text: X12 Source =asdjkasjd file="x/y1.dun" "x/y2.dun" "x/y3.dun" asds12 X22 p/q/xy.dun asda=23 source =asdf X44 1000 1001 file="abc.dun" What I expect using find-and-replace is this: X12 x/y3.dun X22 p/q/xy.dun X44 abc.dun What I have tried so far: (X\d{2}).*?([^"\s]+dun)((?!X\d{2}).)* replace with: $1\t\t$2\n But it returns me this: X12 x/y1.dun //Which is the first match X22 p/q/xy.dun X44 abc.dun

Regex negative lookahead

南笙酒味 提交于 2019-12-23 09:59:07
问题 I need to modify this regex href=\"(.*)\" which matches this... href="./pothole_locator_map.aspx?lang=en-gb&lat=53.153977&lng=-3.533306" To NOT match this... href="./pothole_locator_map.aspx?lang=en-gb&lat=53.153977&lng=-3.533306&returnurl=AbandonedVehicles.aspx" Tried this, but with no luck href=\"(.*)\"(?!&returnurl=AbandonedVehicles.aspx) Any help would be much appreciated. Thanks, Al. 回答1: Lookaheads should be placed before the string is consumed by matching, i.e. href=\"(?!.*&returnurl