Questions tagged [regex-lookarounds]

Regular expression lookarounds are zero-width assertions that verify conditions about the context of a match at the current match position.

Regular expression lookarounds are zero-width assertions that verify conditions about the context of a match. Lookarounds will actually match characters, but then give up the match and only return the result: match or no match. That is why they are called "assertions". They do not consume characters in the string, but only assert whether a match is possible or not.

3265 questions
7
votes
2 answers

ANTLR: Difference between backtrack and look-ahead?

I relative new to ANTLR. I have an very easy grammar: start : ('A' 'B' 'C' '1' |'A' 'B' 'C' '2' |'A' 'B' 'C' '3' ) ; I think that I already understand the basics of the concept of look ahead and backtracking (which works with syntactic…
7
votes
3 answers

Negative lookahead assertion with the * modifier in Perl

I have the (what I believe to be) negative lookahead assertion <@> *(?!QQQ) that I expect to match if the tested string is a <@> followed by any number of spaces (zero including) and then not followed by QQQ. Yet, if the tested string is <@> QQQ the…
René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293
6
votes
4 answers

Regex lookahead

I am using a regex to find: test:? Followed by any character until it hits the next: test:? Now when I run this regex I made: ((?:test:\?)(.*)(?!test:\?)) On this text: test:?foo2=bar2&baz2=foo2test:?foo=bar&baz=footest:?foo2=bar2&baz2=foo2 I…
james
  • 792
  • 7
  • 15
6
votes
5 answers

Regexp matching a string - positive lookahead

Regexp: (?=(\d+))\w+\1 String: 456x56 Hi, I am not getting the concept, how this regex matches "56x56" in the string "456x56". The lookaround, (?=(\d+)), captures 456 and put into \1, for (\d+) The wordcharacter, \w+, matches the whole…
Suresh
  • 1,081
  • 4
  • 21
  • 44
6
votes
4 answers

How to implement LOOP in a FORTH-like language interpreter written in C

I'm writing a simple stack-based language in C and was wondering how I should go about implementing a loop structure of some kind, and/or lookahead symbols. Since the code is a bit long for this page (over 200 lines) I've put it in a GitHub…
tekknolagi
  • 10,663
  • 24
  • 75
  • 119
6
votes
2 answers

Mod Rewrite Regex - Multiple Negative Lookaheads

I currently have the working Mod Rewrite Regex: RewriteEngine On RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*/)?((?:cmd)[^/]*)/((?!(?:cmd)[.+]*)(.+)) $1?$2=$3&%1 [L] That regex takes the following URL and transforms it into the URL…
pb149
  • 2,298
  • 1
  • 22
  • 30
6
votes
2 answers

Regular expression word to match text that includes a word ending in 'ing' but does exclude the words anything, something, nothing

I am coding an app to practice English, I need a javascript regular expression to find all the docs in a mongoDb collection on which the 'answer' property contains a word that ends in ing and exclude a few words from the match like everything,…
Juan Pablo Fernandez
  • 2,408
  • 3
  • 18
  • 32
6
votes
2 answers

Prevent backtracking on regex to find non-comment lines (not starting with indented '#')

I'd like to search for lines that don't start with a pound sign (#) on indented code. Currently, I'm using the regex ^\s*([^\s#].*) with multiline option on. My problem is that on non commented lines it works perfectly. On commented lines the regex…
Bharel
  • 23,672
  • 5
  • 40
  • 80
6
votes
1 answer

Why does .NET's regex engine behave so bizarrely when I omit the "else" from a conditional group?

Code: Match match = Regex.Match("abc", "(?(x)bx)"); Console.WriteLine("Success: {0}", match.Success); Console.WriteLine("Value: \"{0}\"", match.Value); Console.WriteLine("Index: {0}", match.Index); Output: Success: True Value: "" Index: 1 It seems…
Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
6
votes
1 answer

Lazy quantifier and lookahead

I'm working on a regex for validating urls in C#. Right now, the regex I need must not match other http:// but the first one inside the url. This was my first try: (https?:\/\/.+?)\/(.+?)(?!https?:\/\/) But this regex does not work (even removing…
Marco Luzzara
  • 5,540
  • 3
  • 16
  • 42
6
votes
1 answer

Regular expression: matching words between white space

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…
SyntaxError
  • 330
  • 3
  • 16
6
votes
2 answers

Match unescaped quotes in quoted csv

I've looked at several of the Stack Overflow posts with similar titles, and none of the accepted answers have done the trick for me. I have a CSV file where each "cell" of data is delimited by a comma and is quoted (including numbers). Each line…
sundance
  • 2,905
  • 4
  • 21
  • 31
6
votes
2 answers

Java-8 regex negative lookbehind with `\R`

While answering another question, I wrote a regex to match all whitespace up to and including at most one newline. I did this using negative lookbehind for the \R linebreak matcher: ((?
Patrick Parker
  • 4,863
  • 4
  • 19
  • 51
6
votes
3 answers

Replace only the first occurrence of a word with regex in text-editor

I want to replace only first occurrence of word(default) in each line with another word(rwd). As below I want…
Vicky Dev
  • 1,893
  • 2
  • 27
  • 62
6
votes
4 answers

regex to match word (url) only if it does not contain character

I'm using an API that sometimes truncates links inside the text that it returns and instead of "longtexthere https://fancy.link" I get "longtexthere https://fa…". I'm trying to get to match the link only if it's complete, or in other words does not…
kiradotee
  • 1,205
  • 12
  • 20