Many thanks Chris, this really is useful.
I added \t \n \r \f to my copy of your list
Ron

On 3/25/13 6:59 AM, Christopher Stone wrote:
Hey Folks,

From time to time I need to double-check a reference when writing regex, so I've made my own cheat-sheet.

I've got it in Typinator, so I can type an abbreviation and have it instantly in whatever app I'm working in.

Perhaps someone else will find it of use.

I'm also interested in other people's cheat-sheets of all kinds - Perl, Python, Ruby, Shell - whatever.

--
Best Regards,
Chris


————————————————————————————————————————————————————————————————————————————————————————————————————
BBEDIT REGULAR EXPRESSION GUIDE MODIFIED 2011-09-08 : 07:28
————————————————————————————————————————————————————————————————————————————————————————————————————

NOTES: PCRE (Perl Compatible Regular Expressions) is the engine BBEdit uses. Items I'm unsure of are marked '# PCRE?'. The list while fairly comprehensive is not complete.

————————————————————————————————————————————————————————————————————————————————————————————————————
PATTERN MODIFIERS
————————————————————————————————————————————————————————————————————————————————————————————————————
i case insensitive
m allow ^ and $ to match at \r
s allow . to match \r
x ignore most white space and allow inline comments in grep patterns

(?imsx) on
(?-imsx) off
(?i-msx) mixed

————————————————————————————————————————————————————————————————————————————————————————————————————
Regex 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
\S non-whitespace character
\s whitespace character[ \t\n\r\f]
\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
(?<!…) Negative lookbehind assertion
(?()…|…) Match with if-then-else
(?()…) Match with if-then
(?>…) 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:(?<!'pattern')

————————————————————————————————————————————————————————————————————————————————————————————————————
SPECIAL CHARACTER CLASSES (POSIX standard except where 'Perl Extension' is indicated):
————————————————————————————————————————————————————————————————————————————————————————————————————
CLASS MEANING
————————————————————————————————————————————————————————————————————————————————————————————————————
[[:alnum:]] alpha-numeric characters
[[:alpha:]] alphabetic characters
[[:ascii:]] character codes 0-127 # Perl Extension
[[:blank:]] horizontal whitespace
[[:cntrl:]] control characters
[[:digit:]] decimal digits (same as \d)
[[:graph:]] printing characters, excluding spaces
[[:lower:]] lower case letters
[[:print:]] printing characters, including spaces
[[:punct:]] punctuation characters
[[:space:]] white space (same as \s)
[[:upper:]] upper case letters
[[:word:]] word characters (same as \w) # Perl Extension
[[:xdigit:]] hexadecimal digits

[[:alpha:][:digit:]] usage example of multiple character classes

[[:^digit:]]+ NEGATED POSIX-style character class example

** POSIX-style character class names are case-sensitive

** The outermost brackets above indicate a RANGE; the class name itself looks like this: [:alnum:]

————————————————————————————————————————————————————————————————————————————————————————————————————
CONDITIONAL SUBPATTERNS
————————————————————————————————————————————————————————————————————————————————————————————————————

Conditional subpatterns allow you to apply “if-then” or “if-then-else” logic to pattern matching. The “if” portion can either be an integer between 1 and 99, or an assertion.

The forms of syntax for an ordinary conditional subpattern are:

if-then: (?(condition)yes-pattern)
if-then-else: (?(condition)yes-pattern|no-pattern)

and for a named conditional subpattern are:

if-then: (?P<NAME>(condition)yes-pattern)
if-then-else: (?P<NAME>(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”).

————————————————————————————————————————————————————————————————————————————————————————————————————

--
--
You received this message because you are subscribed to the
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem,
please email "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




--
roncattera...@gmail.com

--
--
You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, please email "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

--- You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to