<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SHOCM &#187; regex</title>
	<atom:link href="http://www.shocm.com/tag/regex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shocm.com</link>
	<description>Open Source, Cloud, Scotch, Baseball, Family, and Programming since the 1900&#039;s</description>
	<lastBuildDate>Fri, 27 Apr 2012 15:24:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Learning to Use Regular Expressions by Example</title>
		<link>http://www.shocm.com/2003/08/learning-to-use-regular-expressions-by-example/</link>
		<comments>http://www.shocm.com/2003/08/learning-to-use-regular-expressions-by-example/#comments</comments>
		<pubDate>Sun, 10 Aug 2003 21:47:19 +0000</pubDate>
		<dc:creator>Shocm</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://www.vanjohnson.com/?p=14</guid>
		<description><![CDATA[<p><a href="http://www.phpbuilder.com/contact.php3?contact=dario_at_who.net">Dario F. Gomes</a></p> <p>This site I&#8217;m working on relies heavily on user input through forms, and all that data needs to be checked before being sent a database. I knew PHP3&#8242;s regular expression functions should solve my problem, but I didn&#8217;t know how to form the regular expressions in the first place. What I [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.phpbuilder.com/contact.php3?contact=dario_at_who.net">Dario F. Gomes</a></p>
<p>This site I&#8217;m working on relies heavily on user input through forms, and all that data needs to be checked before being sent a database. I knew PHP3&#8242;s regular expression functions should solve my problem, but I didn&#8217;t know how to form the regular expressions in the first place. What I needed were some sample strings&#8211;obviously the first places I looked were the PHP3 manual and the POSIX 1002.3 specification, but they don&#8217;t help much in the way of exemplifying.<br />
Adding to that, I had a really hard time finding good literature on the Web about the subject. I eventually got to know how to do it, mostly through experimenting, and seeing there wasn&#8217;t much to it, I decided to write down this straight-out introduction to the syntax and a step-by-step on building regular expressions to validate money and e-mail address strings. I just hope it manages to clear the fog around the subject for all you fellow programmers.
</p>
<p><span id="more-14"></span><br />
Basic Syntax of Regular Expressions</p>
<p>First of all, let&#8217;s take a look at two special symbols: &#8216;^&#8217; and &#8216;$&#8217;. What they do is indicate the <em>start</em> and the <em>end</em> of a string, respectively, like this:</p>
<ul>
<li>&#8220;<tt>^The</tt>&#8220;: matches any string that starts with<br />
    &#8220;The&#8221;;</p>
<li>&#8220;<tt>of despair$</tt>&#8220;: matches a string that ends in the<br />
    substring &#8220;of despair&#8221;;</p>
<li>&#8220;<tt>^abc$</tt>&#8220;: a string that starts and ends with &#8220;abc&#8221;<br />
    &#8212; that could only be &#8220;abc&#8221; itself!</p>
<li>&#8220;<tt>notice</tt>&#8220;: a string that has the text &#8220;notice&#8221;<br />
    in it.</li>
</li>
</li>
</li>
</ul>
<p>you don&#8217;t use either of the two characters we mentioned, as in the last example, you&#8217;re saying that the pattern may occur anywhere inside the string &#8212; you&#8217;re not &#8220;hooking&#8221; it to any of the edges.</p>
<p>There are also the symbols &#8216;*&#8217;, &#8216;+&#8217;, and &#8216;?&#8217;, which denote the number of times a character or a sequence of characters may occur. What they mean is:<br />
&#8220;zero or more&#8221;, &#8220;one or more&#8221;, and &#8220;zero or one.&#8221;</p>
<p>Here are some examples:</p>
<ul>
<li>&#8220;<tt>ab*</tt>&#8220;: matches a string that has an <i>a</i> followed<br />
    by zero or more <i>b</i>&#8216;s (&#8220;a&#8221;, &#8220;ab&#8221;, &#8220;abbb&#8221;,<br />
    etc.);</p>
<li>&#8220;<tt>ab+</tt>&#8220;: same, but there&#8217;s at least one <i>b</i> (&#8220;ab&#8221;,<br />
    &#8220;abbb&#8221;, etc.);</p>
<li>&#8220;<tt>ab?</tt>&#8220;: there might be a <i>b</i> or not;
<li>&#8220;<tt>a?b+$</tt>&#8220;: a possible <i>a</i> followed by one or more <i>b</i>&#8216;s ending a string.</li>
</li>
</li>
</li>
</ul>
<p>>bounds, which come inside braces and indicateranges in the number of occurences:</p>
<ul>
<li>&#8220;<tt>ab{2}</tt>&#8220;: matches a string that has an <i>a</i> followed<br />
    by exactly two <i>b</i>&#8216;s (&#8220;abb&#8221;);</p>
<li>&#8220;<tt>ab{2,}</tt>&#8220;: there are at least two <i>b</i>&#8216;s (&#8220;abb&#8221;,<br />
    &#8220;abbbb&#8221;, etc.);</p>
<li>&#8220;<tt>ab{3,5}</tt>&#8220;: from three to five <i>b</i>&#8216;s (&#8220;abbb&#8221;,<br />
    &#8220;abbbb&#8221;, or &#8220;abbbbb&#8221;).</li>
</li>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.shocm.com/2003/08/learning-to-use-regular-expressions-by-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

