<?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>Sentido Web &#187; expresiones regulares</title>
	<atom:link href="http://sentidoweb.com/tag/expresiones-regulares/feed" rel="self" type="application/rss+xml" />
	<link>http://sentidoweb.com</link>
	<description>Desarrollo web, HTML, CSS, Javascript, PHP, MySQL</description>
	<lastBuildDate>Tue, 10 Apr 2012 01:02:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Uso avanzado de expresiones regulares en PHP</title>
		<link>http://sentidoweb.com/2010/04/19/uso-avanzado-de-expresiones-regulares-en-php.php</link>
		<comments>http://sentidoweb.com/2010/04/19/uso-avanzado-de-expresiones-regulares-en-php.php#comments</comments>
		<pubDate>Mon, 19 Apr 2010 13:59:54 +0000</pubDate>
		<dc:creator>displaynone</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[expresiones regulares]]></category>
		<category><![CDATA[regexp]]></category>

		<guid isPermaLink="false">http://sentidoweb.com/?p=2275</guid>
		<description><![CDATA[Interesante y completo tutorial en el que se nos explica usos de las expresiones regulares que normalmente no solemos tener en cuenta: Añadir comentarios preg_match&#40;"/^ (1[-\s.])? # optional '1-', '1.' or '1' ( \( )? # optional opening parenthesis \d{3} # the area code (?(2) \) ) # if there was opening parenthesis, close it [...]]]></description>
			<content:encoded><![CDATA[<p>Interesante y completo tutorial en el que se nos explica usos de las expresiones regulares que normalmente no solemos tener en cuenta:</p>
<h3>Añadir comentarios</h3>
<pre><code><pre class="php"><a href="http://www.php.net/preg_match"><span style="color: #000066;">preg_match</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"/^
    (1[-<span style="color: #000099; font-weight: bold;">\s</span>.])?	# optional '1-', '1.' or '1'
    ( <span style="color: #000099; font-weight: bold;">\(</span> )?		# optional opening parenthesis
    <span style="color: #000099; font-weight: bold;">\d</span>{3}		# the area code
    (?(2) <span style="color: #000099; font-weight: bold;">\)</span> )	# if there was opening parenthesis, close it
    [-<span style="color: #000099; font-weight: bold;">\s</span>.]?		# followed by '-' or '.' or space
    <span style="color: #000099; font-weight: bold;">\d</span>{3}		# first 3 digits
    [-<span style="color: #000099; font-weight: bold;">\s</span>.]?		# followed by '-' or '.' or space
    <span style="color: #000099; font-weight: bold;">\d</span>{4}		# last 4 digits
  $/x"</span>,<span style="color: #3E6D8F;">$number</span><span style="color: #66cc66;">&#41;</span>;</pre></code></pre>
<h3>Callbacks</h3>
<pre><code><pre class="php"><span style="color: #3E6D8F;">$template</span> = <a href="http://www.php.net/preg_replace_callback"><span style="color: #000066;">preg_replace_callback</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/<span style="color: #000099; font-weight: bold;">\[</span>(.*)<span style="color: #000099; font-weight: bold;">\]</span>/'</span>,<span style="color: #ff0000;">'my_callback'</span>,<span style="color: #3E6D8F;">$template</span><span style="color: #66cc66;">&#41;</span>;  
<span style="color: #000000; font-weight: bold;">function</span> my_callback<span style="color: #66cc66;">&#40;</span><span style="color: #3E6D8F;">$matches</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
  <span style="color: #808080; font-style: italic;">/* codigo */</span>
<span style="color: #66cc66;">&#125;</span></pre></code></pre>
<h3>&#8216;Codicia&#8217; de la regexp</h3>
<pre><code><pre class="php"><span style="color: #3E6D8F;">$html</span> = <span style="color: #ff0000;">'&lt;a href=&quot;/hello&quot;&gt;Hello&lt;/a&gt; &lt;a href=&quot;/world&quot;&gt;World!&lt;/a&gt;'</span>;  
<span style="color: #808080; font-style: italic;">// note the ?'s after the *'s  </span>
<span style="color: #723b00;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/preg_match_all"><span style="color: #000066;">preg_match_all</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/&lt;a.*?&gt;.*?&lt;<span style="color: #000099; font-weight: bold;">\/</span>a&gt;/'</span>,<span style="color: #3E6D8F;">$html</span>,<span style="color: #3E6D8F;">$matches</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>  
  <a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #3E6D8F;">$matches</span><span style="color: #66cc66;">&#41;</span>;  
<span style="color: #66cc66;">&#125;</span></pre></code></pre>
<h3>Prefijos y sufijos</h3>
<pre><code><pre class="php"><span style="color: #3E6D8F;">$pattern</span> = <span style="color: #ff0000;">'/foo(?=bar)/'</span>; 
<span style="color: #3E6D8F;">$pattern</span> = <span style="color: #ff0000;">'/foo(?!bar)/'</span>; 
<span style="color: #3E6D8F;">$pattern</span> = <span style="color: #ff0000;">'/(?&lt;!foo)bar/'</span>;</pre></code></pre>
<h3>Condicionales</h3>
<pre><code><pre class="php"><span style="color: #808080; font-style: italic;">// if it begins with 'q', it must begin with 'qu'  </span>
<span style="color: #808080; font-style: italic;">// else it must begin with 'f'  </span>
<span style="color: #3E6D8F;">$pattern</span> = <span style="color: #ff0000;">'/^(?(?=q)qu|f)/'</span>;</pre></code></pre>
<h3>Subpatrones</h3>
<pre><code><pre class="php"><a href="http://www.php.net/preg_match"><span style="color: #000066;">preg_match</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/(?P&lt;hi&gt;H.*) (?P&lt;fstar&gt;f.*)(?P&lt;bstar&gt;b.*)/'</span>, <span style="color: #ff0000;">'Hello foobar'</span>, <span style="color: #3E6D8F;">$matches</span><span style="color: #66cc66;">&#41;</span>;  
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"f* =&gt; "</span> . <span style="color: #3E6D8F;">$matches</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'fstar'</span><span style="color: #66cc66;">&#93;</span>; <span style="color: #808080; font-style: italic;">// prints 'f* =&gt; foo'  </span>
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"b* =&gt; "</span> . <span style="color: #3E6D8F;">$matches</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'bstar'</span><span style="color: #66cc66;">&#93;</span>; <span style="color: #808080; font-style: italic;">// prints 'b* =&gt; bar'  </span>
&nbsp;</pre></code></pre>
<p><a href="http://net.tutsplus.com/tutorials/php/advanced-regular-expression-tips-and-techniques/">Advanced Regular Expression Tips and Techniques</a></p> 
]]></content:encoded>
			<wfw:commentRss>http://sentidoweb.com/2010/04/19/uso-avanzado-de-expresiones-regulares-en-php.php/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Expresiones regulares con filtros en PHP</title>
		<link>http://sentidoweb.com/2009/08/13/expresiones-regulares-con-filtros-en-php.php</link>
		<comments>http://sentidoweb.com/2009/08/13/expresiones-regulares-con-filtros-en-php.php#comments</comments>
		<pubDate>Fri, 14 Aug 2009 03:00:00 +0000</pubDate>
		<dc:creator>displaynone</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[expresiones regulares]]></category>
		<category><![CDATA[filtros]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[regexp]]></category>

		<guid isPermaLink="false">http://sentidoweb.com/2009/08/13/expresiones-regulares-con-filtros-en-php.php</guid>
		<description><![CDATA[Buena alternativa para validar variables usando expresiones regulares usando filtros: Validar números reales $values= array&#40;10.75, '10.75', -1234.5678, 'This is a string', array&#40;&#41;&#41;; $filteredValues = filter_var&#40;$values, FILTER_VALIDATE_FLOAT, FILTER_REQUIRE_ARRAY&#41;; Validar expresiones regulares if&#40;filter_var&#40;$value, FILTER_VALIDATE_REGEXP, array&#40;'options' =&#62; array&#40;'regexp' =&#62; "/^G(.+)/"&#41;&#41;&#41;&#41; &#123; // Lo que sea &#125; Validar URLs $url = 'http://www.devshed.com'; if&#40;filter_var&#40;$url, FILTER_VALIDATE_URL&#41;&#41; &#123; // Lo que sea [...]]]></description>
			<content:encoded><![CDATA[<p>Buena alternativa para validar variables usando expresiones regulares usando filtros:</p>
<ul><li>Validar números reales</li>
</ul>
<pre><code><pre class="php"><span style="color: #3E6D8F;">$values</span>= <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span>.<span style="color: #cc66cc;">75</span>, <span style="color: #ff0000;">'10.75'</span>, -<span style="color: #cc66cc;">1234</span>.<span style="color: #cc66cc;">5678</span>, <span style="color: #ff0000;">'This is a string'</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #3E6D8F;">$filteredValues</span> = filter_var<span style="color: #66cc66;">&#40;</span><span style="color: #3E6D8F;">$values</span>, FILTER_VALIDATE_FLOAT, FILTER_REQUIRE_ARRAY<span style="color: #66cc66;">&#41;</span>;</pre></code></pre>
<ul><li>Validar expresiones regulares</li>
</ul>
<pre><code><pre class="php"><span style="color: #723b00;">if</span><span style="color: #66cc66;">&#40;</span>filter_var<span style="color: #66cc66;">&#40;</span><span style="color: #3E6D8F;">$value</span>, FILTER_VALIDATE_REGEXP, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'options'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'regexp'</span> =&gt; <span style="color: #ff0000;">"/^G(.+)/"</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #808080; font-style: italic;">// Lo que sea</span>
<span style="color: #66cc66;">&#125;</span></pre></code></pre>
<ul><li>Validar URLs</li>
</ul>
<pre><code><pre class="php"><span style="color: #3E6D8F;">$url</span> = <span style="color: #ff0000;">'http://www.devshed.com'</span>;
<span style="color: #723b00;">if</span><span style="color: #66cc66;">&#40;</span>filter_var<span style="color: #66cc66;">&#40;</span><span style="color: #3E6D8F;">$url</span>, FILTER_VALIDATE_URL<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #808080; font-style: italic;">// Lo que sea</span>
<span style="color: #66cc66;">&#125;</span></pre></code></pre>
<p><a href="http://www.devshed.com/c/a/PHP/Working-with-Regular-Expressions-with-Filters-in-PHP-5/">Working with Regular Expressions with Filters in PHP 5</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sentidoweb.com/2009/08/13/expresiones-regulares-con-filtros-en-php.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5 expresiones regulares útiles para desarrollo web</title>
		<link>http://sentidoweb.com/2007/07/23/5-expresiones-regulares-utiles-para-desarrollo-web.php</link>
		<comments>http://sentidoweb.com/2007/07/23/5-expresiones-regulares-utiles-para-desarrollo-web.php#comments</comments>
		<pubDate>Mon, 23 Jul 2007 23:00:00 +0000</pubDate>
		<dc:creator>displaynone</dc:creator>
				<category><![CDATA[Desarrollo web]]></category>
		<category><![CDATA[expresiones regulares]]></category>

		<guid isPermaLink="false">http://sentidoweb.com/2007/07/23/5-expresiones-regulares-utiles-para-desarrollo-web.php</guid>
		<description><![CDATA[Aunque a algunos nos gustan bastante las expresiones regulares, no está mal ofrecer una lista de alguna de ellas que nos pueden ser útiles cuando desarrollamos aplicaciones web. Usuario: está es sencilla, letras, dígitos y el subrayado, con una longitud entre 3 y 16 caracteres. /^[a-zA-Z0-9_]{3,16}$/ Etiquetas XHTML: habrá que sustituir la palabra etiqueta por [...]]]></description>
			<content:encoded><![CDATA[<p>Aunque a algunos nos gustan bastante las expresiones regulares, no está mal ofrecer una lista de alguna de ellas que nos pueden ser útiles cuando desarrollamos aplicaciones web.</p>
<ul><li>Usuario: está es sencilla, letras, dígitos y el subrayado, con una longitud entre 3 y 16 caracteres.</li></ul>
<pre>/^[a-zA-Z0-9_]{3,16}$/</pre>
<ul><li>Etiquetas XHTML: habrá que sustituir la palabra <em>etiqueta</em> por la correspondiente que queremos buscar.</li></ul>
<pre>/<etiqueta[^>]*>(.*?)<\/etiqueta>/</pre>
<ul><li><strong>Etiqueta con atributos</strong>: lo mismo que la anterior pero con atributos.</li></ul>
<pre>/<etiqueta[^>]*atributo\s*=\s*(["'])valor\\1[^>]*>(.*?)<\/etiqueta>/</pre>
<ul><li><strong>Direcciones de correo</strong>: según la especificación <a href="http://www.faqs.org/rfcs/rfc822.html">RFC 822</a>:</li></ul>
<pre><code>function is_valid_email_address($email){
$qtext = '[^\x0d\x22\x5c\x80-\xff]';
$dtext = '[^\x0d\x5b-\x5d\x80-\xff]';
$atom = '[^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c'.
'\x3e\x40\x5b-\x5d\x7f-\xff]+';
$quoted_pair = '\x5c[\x00-\x7f]';
$domain_literal = "\x5b($dtext|$quoted_pair)*\x5d";
$quoted_string = "\x22($qtext|$quoted_pair)*\x22";
$domain_ref = $atom;
$sub_domain = "($domain_ref|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(\x2e$sub_domain)*";
$local_part = "$word(\x2e$word)*";
$addr_spec = "$local_part\x40$domain";
return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
}</code></pre>
<ul><li><strong>URL</strong>: para reconocer direcciones de internet:</li></ul>
<pre>{
\b
# Parte principal (protocolo://dominio, o solo dominio)
(
# http://, o https://
(https?)://[-\w]+(\.\w[-\w]*)+
|
# Nombre de dominio
(?i: [a-z0-9] (?:[-a-z0-9]*[a-z0-9])? \. )+ # subdominions
# .com, .net...
(?-i: com\b
| edu\b
| biz\b
| gov\b
| in(?:t|fo)\b # .int or .info
| mil\b
| net\b
| org\b
| [a-z][a-z]\.[a-z][a-z]\b # two-letter country code
)
)
# Puerto
( : \d+ )?
# El resto es opcional que empieza por /
(
/
[^.!,?;"\'<>()[]{}sx7F-\xFF]*
(
[.!,?]+ [^.!,?;”\’<>()\[\]{\}s\x7F-\xFF]+
)*
)?
}ix</pre>
<p><a href="http://immike.net/blog/2007/04/06/5-regular-expressions-every-web-programmer-should-know/">5 Regular Expressions Every Web Programmer Should Know</a></p>
<p>Vía / <a href="http://www.dzone.com/rsslinks/5_regular_expressions_every_web_programmer_should.html">dzone</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sentidoweb.com/2007/07/23/5-expresiones-regulares-utiles-para-desarrollo-web.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expresiones regulares en PHP</title>
		<link>http://sentidoweb.com/2006/09/26/expresiones-regulares-en-php.php</link>
		<comments>http://sentidoweb.com/2006/09/26/expresiones-regulares-en-php.php#comments</comments>
		<pubDate>Tue, 26 Sep 2006 17:00:00 +0000</pubDate>
		<dc:creator>displaynone</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[expresiones regulares]]></category>
		<category><![CDATA[php expresiones regulares]]></category>

		<guid isPermaLink="false">http://sentidoweb.com/2006/09/26/expresiones-regulares-en-php.php</guid>
		<description><![CDATA[Creo que uno de los mejores inventos en la programación son las expresiones regulares, en otra ocasión ya hemos hablado de ellas, pero esta vez os mostramos un enlace bastante interesante en el que se nos explica su uso en PHP. Aunque no se trata solamente del uso de funciones, sino también una lista de [...]]]></description>
			<content:encoded><![CDATA[Creo que uno de los mejores inventos en la programación son las expresiones regulares, en otra <a href="http://sentidoweb.com/2006/07/11/regulazy-una-ayuda-para-tus-expresiones-regulares.php">ocasión</a> ya hemos hablado de ellas, pero esta vez os mostramos un enlace bastante interesante en el que se nos explica su uso en PHP.
Aunque no se trata solamente del uso de funciones, sino también una lista de recursos, como este <a href="http://perldoc.perl.org/perlretut.html">manual de expresiones regulares en Perl</a>, en el cual recomiendo el apartado sobre <a href="http://perldoc.perl.org/perlretut.html#Non-capturing-groupings">grupos no capturables</a> (no los solemos usar pero creo que son fundamentables), y también nos habla de la diferencia entre expresiones regulares POSIX y compatibles con Perl.
Se trata de un primer artículo y al menos deberá haber uno más, que espero sea tan bueno como este.
<a href="http://www.sitepoint.com/blogs/2006/09/26/the-joy-of-regular-expressions-1/">The Joy of Regular Expressions [1]</a>
<a href="http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/">The Joy of Regular Expressions [2]</a> <strong>(actualización)</strong>
<a href="http://www.sitepoint.com/blogs/2006/09/28/the-joy-of-regular-expressions-3/">The Joy of Regular Expressions [3]</a> <strong>(actualización)</strong>
]]></content:encoded>
			<wfw:commentRss>http://sentidoweb.com/2006/09/26/expresiones-regulares-en-php.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regulazy: una ayuda para tus expresiones regulares</title>
		<link>http://sentidoweb.com/2006/07/11/regulazy-una-ayuda-para-tus-expresiones-regulares.php</link>
		<comments>http://sentidoweb.com/2006/07/11/regulazy-una-ayuda-para-tus-expresiones-regulares.php#comments</comments>
		<pubDate>Tue, 11 Jul 2006 17:11:38 +0000</pubDate>
		<dc:creator>displaynone</dc:creator>
				<category><![CDATA[Curiosidades]]></category>
		<category><![CDATA[expresiones regulares]]></category>
		<category><![CDATA[expresiones regulares programa]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://sentidoweb.com/2006/07/11/regulazy-una-ayuda-para-tus-expresiones-regulares.php</guid>
		<description><![CDATA[Supongo que no todo el mundo es un adicto a las expresiones regulares como lo puedo ser yo, y la verdad es que si no te gustan, son un poco difíciles de entender. Si eres de ese grupo, te vendrá bastante bien una aplicación que te ayude con las expresiones regulares: Regulazy. El funcionamiento es [...]]]></description>
			<content:encoded><![CDATA[Supongo que no todo el mundo es un adicto a las expresiones regulares como lo puedo ser yo, y la verdad es que si no te gustan, son un poco difíciles de entender. Si eres de ese grupo, te vendrá bastante bien una aplicación que <strong>te ayude con las expresiones regulares</strong>: Regulazy.
<img alt="RegulazyDemo.gif" src="http://sentidoweb.com/img/2006/07/RegulazyDemo.gif" width="352" height="240" class="center"/>
El funcionamiento es sencillo, escribes una frase, la cual debería reconocer la expresión regular y luego modificas las partes indicando si quieres que reconozca tal palabra de forma exacta, o si realmente puede ser una unión de números y letras, o si puede ser cualquier cosa.
<a href="http://tools.osherove.com/Default.aspx?tabid=182">Regulazy</a>
Vía / <a href="http://www.sitepoint.com/blogs/2006/07/11/regulazy%e2%80%94regular-expressions-for-the-rest-of-us/">SitePoint</a>
]]></content:encoded>
			<wfw:commentRss>http://sentidoweb.com/2006/07/11/regulazy-una-ayuda-para-tus-expresiones-regulares.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

