Your SlideShare is downloading. ×
Regex cheatsheet
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Regex cheatsheet

843
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
843
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Regular Expressions - Quick Reference Guide Anchors Literal Characters ^ Character group contents start of line $ end of line Letters and digits match exactly axB70 x individual chars b word boundary Some special characters match exactly @-=% x-y character range B not at word boundary [:class:] posix char class A start of subject Escape other specials with backslash . $ [ G first match in subject [^:class:] negated class z end of subject Character Groups Z end of subject Almost any character (usually not newline) . Examples or before newline at end [a-zA-Z0-9_] Lists and ranges of characters [ ] Non-printing characters Any character except those listed [^ ] [[:alnum:]_] a alarm (BEL, hex 07) cx "control-x" e escape (hex 1B) Counts (add ? for non-greedy) Comments f formfeed (hex 0C) 0 or more ("perhaps some") * (?#comment) n newline (hex 0A) 0 or 1 ("perhaps a") ? r carriage return (hex OD) t 1 or more ("some") + Conditional subpatterns tab (hex 09) ddd octal code ddd Between "n" and "m" of {n,m} (?(condition)yes-pattern) xhh hex code hh Exactly "n", "n" or more {n}, {n,} (?(condition)yes|no-pattern) x{hhh..} hex code hhh.. Generic character types Alternation Recursive patterns d decimal digit Either/or | (?n) Numbered D not a decimal digit (?0) (?R) Entire regex s whitespace character S Lookahead and Lookbehind (?&name) Named not a whitespace char w "word" character Followed by (?= ) W "non-word" character NOT followed by (?! ) Replacements POSIX character classes Following (?<= ) $n reference capture alnum letters and digits NOT following (?<! ) alpha letters Case foldings ascii character codes 0-127 blank Grouping u upper case next char space or tab only cntrl control characters For capture and counts ( ) U upper case following digit decimal digits Non-capturing (?: ) l lower case next char graph printing chars -space L lower case following lower lower case letters Named captures (?<name> ) print printing chars +space Alternation E end case folding punct printing chars -alnum Back references space white space Conditional insertions upper Numbered n gn g{n} upper case letters (?n:insertion) word "word" characters Relative g{-n} xdigit hexadecimal digits Named k<name> (?n:insertion:otherwise) http://www.e-texteditor.com