———————————————————————————————————————————————————————————————————————————————————————————————————— BBEDIT REGULAR EXPRESSION GUIDE MODIFIED 2013-03-27 : 13:08 ———————————————————————————————————————————————————————————————————————————————————————————————————— NOTES: The PCRE (Perl Compatible Regular Expressions) engine is what BBEdit uses. Items I'm unsure of are marked '# PCRE?'. The list while fairly comprehensive is not complete. ———————————————————————————————————————————————————————————————————————————————————————————————————— PATTERN MODIFIERS (switches) ———————————————————————————————————————————————————————————————————————————————————————————————————— i Case-insensitive m Multiline : allow the grep engine to match at ^ and $ after and before at \r or \n. s Magic Dot : allows . to match \r and \n x Free-spacing: ignore unescaped white space; allow inline comments in grep patterns. (?imsx) On (?-imsx) Off (?i-msx) Mixed ———————————————————————————————————————————————————————————————————————————————————————————————————— Regex Meta-Characters: ———————————————————————————————————————————————————————————————————————————————————————————————————— . Any character except newline or carriage return [ ] Any single character of set [^ ] Any single character NOT of set * 0 or more previous regular expression *? 0 or more previous regular expression (non-greedy) + 1 or more previous regular expression +? 1 or more previous regular expression (non-greedy) ? 0 or 1 previous regular expression | Alternation ( ) Grouping regular expressions ^ Beginning of a line or string $ End of a line or string {m,n} At least m but most n previous regular expression {m,n}? At least m but most n previous regular expression (non-greedy) \1-9 Nth previous captured group \& Whole match # BBEdit: '&' only - no escape needed \` Pre-match # PCRE? NOT BBEdit \' Post-match # PCRE? NOT BBEdit \+ Highest group matched # PCRE? NOT BBEdit \A Beginning of a string \b Backspace(0x08)(inside[]only) # PCRE? \b Word boundary(outside[]only) \B Non-word boundary \d Digit, same as[0-9] \D Non-digit ———————————————————————————————————————————————————————————————————————————————————————————————————— Case-Change Operators ———————————————————————————————————————————————————————————————————————————————————————————————————— \E Change case - acts as an end delimiter to terminate runs of \L & \U. \l Change case of only the first character to the right lower case. (Note: lowercase 'L') \L Change case of all text to the right to lowercase. \u Change case of only the first character to the right to uppercase. \U Change case of all text to the right to uppercase. ———————————————————————————————————————————————————————————————————————————————————————————————————— White-Space or Non-White-Space ———————————————————————————————————————————————————————————————————————————————————————————————————— \t Tab \n Linefeed \r Return \f Formfeed \s Whitespace character equivalent to [ \t\n\r\f] \S Non-whitespace character ———————————————————————————————————————————————————————————————————————————————————————————————————— \W Non-word character \w Word character[0-9A-Za-z_] \z End of a string \Z End of a string, or before newline at the end (?#) Comment (?:) Grouping without backreferences (?=) Zero-width positive look-ahead assertion (?!) Zero-width negative look-ahead assertion (?>) Nested anchored sub-regexp stops backtracking (?imx-imx) Turns on/off imx options for rest of regexp (?imx-imx:…) Turns on/off imx options, localized in group # '…' indicates added regex pattern ———————————————————————————————————————————————————————————————————————————————————————————————————— PERL-STYLE PATTERN EXTENSIONS : BBEdit Documentation : '…' indicates added regex pattern ———————————————————————————————————————————————————————————————————————————————————————————————————— Extension Meaning ———————————————————————————————————————————————————————————————————————————————————————————————————— (?:…) Cluster-only parentheses, no capturing (?#…) Comment, discard all text between the parentheses (?imsx-imsx) Enable/disable pattern modifiers (?imsx-imsx:…) Cluster-only parens with modifiers (?=…) Positive lookahead assertion (?!…) Negative lookahead assertion (?<=…) Positive lookbehind assertion (?…) Match non-backtracking subpattern (“once-only”) (?R) Recursive pattern ———————————————————————————————————————————————————————————————————————————————————————————————————— POSITIONAL ASSERTIONS (duplicatation of above) ———————————————————————————————————————————————————————————————————————————————————————————————————— POSITIVE LOOKAHEAD ASSERTION: (?='pattern') NEGATIVE LOOKAHEAD ASSERTION: (?!'pattern') POSITIVE LOOKBEHIND ASSERTION: (?<='pattern') # Lookbehind Assertions are of fixed-length NEGATIVE LOOKBEHIND ASSERTION: (?(condition)yes-pattern) if-then-else: (?P(condition)yes-pattern|no-pattern) If the condition evaluates as true, the “yes-pattern” portion attempts to match. Otherwise, the “no-pattern” portion does (if there is a “no-pattern”). ————————————————————————————————————————————————————————————————————————————————————————————————————