RegEx Lookup

Some quick reference for Regular Expressions:

 

/ / delimiters of the pattern

+ one or more of the preceding character

* zero or more of the preceding character

? zero or one occurence of the preceding character

[] match one of a group of alternatives

\ escape a special character

^ match at the beginning of the string

$ match at the end of the string

/^ $/ match entire string

\b match at word boundary

\B not at word boundary – opposite to \b

[^ ] excluding a set of alternatives

\d any digit

\D anything other than digit

\w any word character [_0-9a-zA-Z]

\W anything other than word character

\s whitespace

\S anything other than whitespace

. anything except newline

{n} n number of occurences of the preceding character

| OR operation

\1 \2 … saved patterns

 

PATTERN MATCHING OPTIONS:

 

/g match all possible patterns

/i ignore case

/m treat string as multiple lines

/o only evaluate once

/s treat string as single line

/x ignore white space in pattern

 

PATTERN SUBSTITUTION AND OPTIONS:

 

s/ substitution operator

 

/g change all occurences of the pattern

/i ignore case in pattern

/e evaluate replacement string as expression

/m treat string to be matched as multiple lines

/o evaluate only once

/s treat string to be matched as single line

/x ignore white space in pattern

 

TRANSLATION AND OPTIONS:

 

tr/ translation

 

/c complement

/d delete all specified characters

/s squeeze-replace multiple identical output characters with a single character

 

EXTENDED PATTERN MATCHING:

 

(?: ) do not save the pattern in memory

 

EMBEDDED OPTIONS:

 

/(?i) = /i

/(?m) = /m

/(?s) = /s

/(?x) = /x

 

LOOK AHEAD:

 

(?= ) positive look ahead

(?! ) negative look ahead

(?# ) comments within pattern

 

~There’s more than one way to do it~TMTOWTDI

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: