negative-lookahead

Positive/Negative lookahead with grep and perl

我怕爱的太早我们不能终老 提交于 2019-12-09 14:48:04
问题 my login.txt file contains following entries abc def abc 123 def abc abc de tha ewe when i do the positive lookahead using perl, i'm getting the following result cat login.txt | perl -ne 'print if /(?)abc\s(?=def)/' abc def when i use grep i'm getting the following result cat login.txt | grep -P '(?<=abc)\s(?=def)' abc def negative lookahed results as follows from perl and grep. cat login | perl -ne 'print if /(?)abc\s(?!def)/' abc 123 def abc abc de grep result cat login.txt | grep -P '(?<

Regex: what does (?! …) mean?

只谈情不闲聊 提交于 2019-12-09 08:05:29
问题 The following regex finds text between substrings FTW and ODP. /FTW(((?!FTW|ODP).)+)ODP+/ What does the (?! ... ) do? 回答1: (?!regex) is a zero-width negative lookahead. It will test the characters at the current cursor position and forward, testing that they do NOT match the supplied regex, and then return the cursor back to where it started. The whole regexp: / FTW # Match Characters 'FTW' ( # Start Match Group 1 ( # Start Match Group 2 (?!FTW|ODP) # Ensure next characters are NOT 'FTW' or

Star vs. plus quantifier in the variable-width negative lookbehind

邮差的信 提交于 2019-12-08 06:35:51
问题 Silly question here... I'm trying to match white-space inside the line while ignoring the leading spaces/tabs and came up with these regex strings, but I can't figure out why only one is working (C# regex engine): (?<!^[ \t]*)[ \t]+ // regex 1. (with *) (?<!^[ \t]+)[ \t]+ // regex 2. (with +) Note the star vs. plus repetitions in the negative look-ahead . When matching these against " word1 word2" (2 leading spaces): ⎵⎵word1⎵word2 ^ // 1 match for regex 1. (*) ⎵⎵word1⎵word2 ^^ ^ // 2 matches

POSIX Regular Expressions: Excluding a word in an expression?

谁说我不能喝 提交于 2019-12-07 06:52:07
问题 I am trying to create a regular expression using POSIX (Extended) Regular Expressions that I can use in my C program code. Specifically, I have come up with the following, however, I want to exclude the word "http" within the matched expressions. Upon some searching, it doesn't look like POSIX makes it obvious for catching specific strings. I am using something called a "negative look-a-head" in the below example (i.e. the (?!http:) ). However, I fear that this may only be something available

.NET Regex Negative Lookahead - what am I doing wrong?

懵懂的女人 提交于 2019-12-04 06:46:20
问题 Assuming I have: StartTest NoInclude EndTest StartTest Include EndTest and am using: /StartTest(?!NoInclude)[\s\S]*?EndTest/g Why am I matching both groups? Regexr example: http://regexr.com/3db8m 回答1: You fail the match with the lookahead if NoInclude appears straight after StartTest . You need a tempered greedy token: (?s)StartTest(?:(?!(?:Start|End)Test|NoInclude).)*EndTest ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ See the regex demo The regex is matching StartTest , then matches any text that

Regular expressions negative lookahead

▼魔方 西西 提交于 2019-12-04 04:20:18
I'm doing some regular expression gymnastics. I set myself the task of trying to search for C# code where there is a usage of the as-operator not followed by a null-check within a reasonable amount of space. Now I don't want to parse the C# code. E.g. I want to capture code snippets such as var x1 = x as SimpleRes; var y1 = y as SimpleRes; if(x1.a == y1.a) however, not capture var x1 = x as SimpleRes; var y1 = y as SimpleRes; if(x1 == null) nor for that matter var x1 = x as SimpleRes; var y1 = y as SimpleRes; if(somethingunrelated == null) {...} if(x1.a == y1.a) Thus any random null-check will

Positive/Negative lookahead with grep and perl

被刻印的时光 ゝ 提交于 2019-12-04 00:27:15
my login.txt file contains following entries abc def abc 123 def abc abc de tha ewe when i do the positive lookahead using perl, i'm getting the following result cat login.txt | perl -ne 'print if /(?)abc\s(?=def)/' abc def when i use grep i'm getting the following result cat login.txt | grep -P '(?<=abc)\s(?=def)' abc def negative lookahed results as follows from perl and grep. cat login | perl -ne 'print if /(?)abc\s(?!def)/' abc 123 def abc abc de grep result cat login.txt | grep -P '(?<=abc)\s(?!def)' abc 123 abc de perl matched the def abc for the negative lookahead. but it shouldn't

Javascript regular expression: match anything up until something (if there it exists)

旧巷老猫 提交于 2019-12-03 16:48:10
问题 Hi I am new to regular expression and this may be a very easy question (hopefully). I am trying to use one solution for 3 kind of string "45%", expected result: "45" "45", expected result: "45" "", expected result: "" What I am trying (let the string be str): str.match(/(.*)(?!%*)/i)[1] This in my head would sound like "match any instance of anything up until '%' if it is found, or else just match anything" In firebug's head it seems to sound more like "just match anything and completely

Negative look ahead python regex

回眸只為那壹抹淺笑 提交于 2019-12-03 12:10:31
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 = 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[

Javascript regular expression: match anything up until something (if there it exists)

北城余情 提交于 2019-12-03 06:07:59
Hi I am new to regular expression and this may be a very easy question (hopefully). I am trying to use one solution for 3 kind of string "45%", expected result: "45" "45", expected result: "45" "", expected result: "" What I am trying (let the string be str): str.match(/(.*)(?!%*)/i)[1] This in my head would sound like "match any instance of anything up until '%' if it is found, or else just match anything" In firebug's head it seems to sound more like "just match anything and completely disregard the negative lookahead". Also to make it lazy - (.*)? - doesn't seem to help. Let's forget for a