please dont rip this site

Regular Expressions

Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems. --Jamie Zawinski, in comp.lang.emacs

Used to extremes in Perl. Available in many languages. The following is designed as a quick reference / memory jog for experienced RE users. Any new users should... A) find another solution B) copy existing working code C) join a newsgroup or mailing list and ask for help D) take a class. RE is like shaking hands with an octopus.

^	beginning
$	end
.	any character
[.-.]	any character from the first "." to the second where . is any character
	e.g. [A-Z] matches any uppercase letter

\.	Quote. Treats "." as a literal value where . is any character
	e.g. \$ matches the dollar sign, not the end of line.
\###	Byte where ### are three octal digits.
\x##	Byte where ## are two hexadecimal digits.

Flow control
(.*)	Group. Matches everything in the parens or nothing. Saves the match in $# were # 
	counts up the groups. 
	e.g. Time: (..):(..):(..) will put the hours in $1, minutes in $2 and seconds in $3.
.*|.*	Or. If the pattern before the "|" fails to match, it will try the pattern after.
	e.g. A|B will match A or B

*	0 or more times. Same as {0,}. Will "eat" to the end unless followed by ? or something else
+	1 or more times. Same as {1,}. Will "eat" to the end unless followed by ? or something else
?	0 or 1 times. Same as {0,1}
{n}	Match exactly n times
{n,}	Match at least n times. Will "eat" to the end unless followed ? or something else
{n,m}	Match at least n but not more than m times.
.*?	Match the minimum number of times possible where .* is one of the repeat patterns above.
	e.g. foo(.*)bar used against "the food is barbecued in the barn" will set $1 to "d is barbecued in the "
	 but foo(.*?)bar will set it to "d is ". Notice
	 that foo(.*)barb will also produce "d is "

For a regular expression to match, the entire regular expression must match, not just part of it. So if the beginning of a pattern containing a quantifier succeeds in a way that causes later parts in the pattern to fail, the matching engine backs up and recalculates the beginning part--that's why it's called backtracking.


See also:


City state zip \s*(.*)\s*,\s*([A-Z]{{2}})\s+(\d{{5}}(\-\d{{4}})?)\s*"
HTML eMail
with only an
image in it
The following expression will match a message that contains one or more images and no text at all:
HTML eMail
with an image

IPv4 dotted IP address: Anything from "/^\d+\.\d+\.\d+\.\d+$/" (which allows "448.90210.0.65535") to "/^([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])$/" which is impossible for normal humans to understand. +


file: /Techref/language/regxs.htm, 5KB, , updated: 2012/11/16 13:28, local time: 2017/10/23 23:08,

 ©2017 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE! / 

<A HREF=""> Regular Expressions</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2017 contributors:
o List host: MIT, Site host, Top posters @20171023 RussellMc, Van Horn, David, James Cameron, Sean Breheny, IVP, alan.b.pearce, Neil, David C Brown, Bob Blick, Denny Esterline,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.

Welcome to!