asp.net.ph

Skip Navigation LinksGetting Started > ASP.NET Base Types > Regular Expressions > Details of Regular Expression Behavior > Nonbacktracking Lookahead and Lookbehind

Nonbacktracking Lookahead and Lookbehind

Getting Started   ASP.NET Base Types   Details of Regular Expression Behavior


Positive lookahead and lookbehind do not backtrack. That is, their contents are treated in the same way as the contents of a nonbacktracking ( ?> ) group.

Since lookahead and lookbehind are always zero-width, backtracking behavior is visible only when capturing groups appear within positive lookahead and lookbehind. For example, the expression ( ?= ( a* ) ) \1a will never find a match because group 1, which is defined within the lookahead, consumes as many "a" characters as there are, then \1a requires one more. Because the lookahead expression is not backtracked, the matching engine does not retry group 1 with fewer "a" characters.

For more on grouping, lookahead, and lookbehind constructs, see Grouping Constructs

See Also

Regular Expressions



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note