Capturing groups and searches

I want to know how capture groups (or non-capture ones) affect search queries in Regex. Here are two examples:

test (?:(?!<start).)+

test (?!<start).+

I would appreciate it if anyone could explain how the regex mechanism interprets both cases in detail.

+3
source share
1 answer
  • Appearance zero width . In this regard, it makes no sense to place them yourself inside the capture group, they do not capture anything more interesting than an empty line (just like \b vs. (\b).. backlink to an optional group, but this is not very interesting.
  • looharounds - (?=...) (?<=...) - . , /(?=(\b\w+\b))/ , . , /(?<=(.))\1/ , .
  • looharounds - (?!...) (?<!...) - . , , , . , ^(?!.*(.).*\1).*$ , . , \1, .

, . :

  • (?:(?!<start).)+ - , start, (). :

    • "start1234end", - "".
    • "before123startAfter" , "before123start" ( ), : "fter".
  • (?:(?!<start).)+ - lookbehind ( : (?:...)+ , ). , start:

    • "start1234end" - "start". '1' ( , start), . "234end".
+3

All Articles