My RegEx Notes

Selecting string between two markers

(?<=Marker1).*(?=Marker2)

(?<=   ) is called Positive Lookbehind
.*  matches any character (except for line terminators)
(?=   )   is called Positive Lookahead

Keeping exactly one space + trim trailing + trim leading spaces

Key to search
^\s+|\s+$|\s+(?=\s)

^ = start of line
\s = searches for a space
+ = matches between one and unlimited times
^\s+ = From start of line select spaces (one to unlimited)

$ = Till end of line
\s+$ = From a space till end of line

(?=   )   is called Positive Lookahead
\s+(?=\s) = Select more than one space

Comments