<?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>Weekend Projects | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/category/weekend-projects/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Sat, 14 Feb 2015 10:31:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>RegExpBuilderPHP &#8211; PHP Regular Expression Builder</title>
		<link>https://nerdpress.org/2015/02/13/regexpbuilderphp-php-regular-expression-builder/</link>
					<comments>https://nerdpress.org/2015/02/13/regexpbuilderphp-php-regular-expression-builder/#comments</comments>
		
		<dc:creator><![CDATA[Max Girkens]]></dc:creator>
		<pubDate>Fri, 13 Feb 2015 14:38:45 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Weekend Projects]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2625</guid>

					<description><![CDATA[<p>There this really useful tool for JS, called RegExpBuilder. It enables you to build regular expressions with a nice human-readable &#038; chainable syntax. (read more about it here and here) As it&#8217;s not that much lines of code, I decided to do a port for PHP &#8211; et voila: https://github.com/gherkins/regexpbuilderphp This is basically regex with &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2015/02/13/regexpbuilderphp-php-regular-expression-builder/" class="more-link">Continue reading<span class="screen-reader-text"> "RegExpBuilderPHP &#8211; PHP Regular Expression Builder"</span></a></p>
The post <a href="https://nerdpress.org/2015/02/13/regexpbuilderphp-php-regular-expression-builder/">RegExpBuilderPHP – PHP Regular Expression Builder</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>There this really useful tool for JS, called <a href="https://github.com/thebinarysearchtree/regexpbuilderjs/">RegExpBuilder</a>.<br />
It enables you to build regular expressions with a nice human-readable &#038; chainable syntax.<br />
(read more about it <a href="http://thebinarysearchtree.blogspot.de/2012/06/regexpbuilder.html">here</a> and <a href="https://github.com/thebinarysearchtree/regexpbuilderjs/wiki">here</a>)</p>
<p>As it&#8217;s not that much lines of code, I decided to do a port for PHP &#8211; et voila:</p>
<p><a href="https://github.com/gherkins/regexpbuilderphp">https://github.com/gherkins/regexpbuilderphp</a><br />
<span id="more-2625"></span></p>
<p>This is basically regex with PHP the easy way:</p>
<p>Say you want to validate some currency string like &#8220;€ 105,99&#8221; but want &#8220;€ 12.000,95&#8221; to be also valid.<br />
Coming up with a regex for that i would find challenging, to say the least.</p>
<p>PHP RegExpBuilder to the rescue:</p>
<p>(you can simply install it via composer)</p>
<pre class="brush: bash; title: ; notranslate">composer require gherkins/regexpbuilderphp:dev-master</pre>
<p>Then you&#8217;ll be able to do:</p>
<pre class="brush: php; title: ; notranslate">
$builder = new \Gherkins\RegExpBuilderPHP\RegExpBuilder();


    $builder1 = $builder
        -&gt;find(&quot;€&quot;)
        -&gt;exactly(1)-&gt;whitespace()
        -&gt;min(1)-&gt;digits()
        -&gt;then(&quot;,&quot;)
        -&gt;digit()
        -&gt;digit();
        
    //builder 1 will take care of the cases without a thousand-seperator

    $builder1-&gt;getRegExp()-&gt;test(&quot;€ 128,99&quot;);     //true
    $builder1-&gt;getRegExp()-&gt;test(&quot;€ 81,99&quot;);      //true
        
       
                     
    $builder2 = $builder-&gt;getNew()
        -&gt;find(&quot;€&quot;)
        -&gt;exactly(1)-&gt;whitespace()
        -&gt;min(1)-&gt;digits()
        -&gt;then(&quot;.&quot;)
        -&gt;exactly(3)-&gt;digits()
        -&gt;then(&quot;,&quot;)
        -&gt;digit()
        -&gt;digit();
        
    //builder 1 will take care of the cases *with* the thousand-seperator

    $builder2-&gt;getRegExp()-&gt;test(&quot;€ 1.228,99&quot;);   //true
    $builder2-&gt;getRegExp()-&gt;test(&quot;€ 452.000,99&quot;); //true
        
        
    //you can then combine both builders to get a regex which handles all cases:
       
    $combined = $this-&gt;r-&gt;getNew()
        -&gt;either($builder1)
        -&gt;orLike($builder2);
        
    $combined-&gt;getRegExp()-&gt;test(&quot;€ 128,99&quot;);     //true
    $combined-&gt;getRegExp()-&gt;test(&quot;€ 81,99&quot;);      //true
    $combined-&gt;getRegExp()-&gt;test(&quot;€ 1.228,99&quot;);   //true
    $combined-&gt;getRegExp()-&gt;test(&quot;€ 452.000,99&quot;); //true
</pre>
<p>This might be a bit verbose if you don&#8217;t have any problem with:</p>
<pre class="brush: bash; title: ; notranslate">
(?:(?:(?:(?:€){1,1})(?:(?:\s){1,1})(?:(?:(?:\d)){1,})(?:(?:,){1,1})(?:\d)(?:\d))|(?:(?:(?:€){1,1})(?:(?:\s){1,1})(?:(?:(?:\d)){1,})(?:(?:\.){1,1})(?:(?:(?:\d)){3,3})(?:(?:,){1,1})(?:\d)(?:\d)))
</pre>
<p>..but I really do like it ;)</p>
<p><a href="https://github.com/gherkins/regexpbuilderphp">https://github.com/gherkins/regexpbuilderphp</a></p>The post <a href="https://nerdpress.org/2015/02/13/regexpbuilderphp-php-regular-expression-builder/">RegExpBuilderPHP – PHP Regular Expression Builder</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2015/02/13/regexpbuilderphp-php-regular-expression-builder/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
