Lookforward and Lookbehind When Using Regular Expressions

Regular expressions are a great tool for identifying strings. There are some special cases called ‚lookahead‘ and ‚lookbehind‘, that are described below:

Lookahead

The current position is followed by “test”:

(?=test)    

Lookbehind

“test” is before the current position:

(?<=test)   

Negative Lookahead

The current position is not followed by “test”:

(?!test)    

Negative Lookbehind

“test” is not before the current position:

(?<!test)