Strictly Programming

Notes on the Regular Expression

Posted in Uncategorized by sqllyw on 11/24/2008

Here are some notes on the use of Regular Expression, more specifically on its use with Groovy.


Basic Pattern Symbols

.		any letter
^		Start of line(or start of document, when in single-line mode)
$		End of line(or end of document, when in single-line mode)
\d		Digit character
\D		Any character except digits
\s		Whitespace character
\S		Any character except whitespace
\w		Word character
\W		any character except word characters
\b		Word boundary
()		Grouping
(x|y)	x or y, as in (Groovy|Java|R)
\1		Backmatch to group one: for example, find doubled characters with (.)\1
x*		Zero or more occurrences of x
x+		One or more occurrences of x
x?		Zero or one occurrences of x
x{m,n}	At least m and at most n occurrences of x
x{m}	Exactly m occurrences of x
[a-f]	Character class containing the characters a,b,c,d,e,f
[^a]	Character class containing any character except a
[?is:x]	Switches mode when evaluating x, i - turns on ignoreCase, 
										 s - means single line mode

Note:
Symbols tent to have the same first leter as what they represent:
for example, (d)igit, (s)pace, (w)ord, and (b)oundry. Upercase symbols defined
the complement; think of them as a warning sign for no.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

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: