<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/1.5.1-alpha" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Regular Expression - 正規表現</title>
	<link>http://hungnv.blogsome.com/2007/01/05/p90/</link>
	<description>Những điều nghe, nhìn và suy ngẫm được tôi đưa lên vào những lúc thư nhàn.</description>
	<pubDate>Wed, 09 Dec 2009 07:12:57 +0000</pubDate>
	<generator>http://wordpress.org/?v=1.5.1-alpha</generator>

	<item>
		<title>by: hungnv</title>
		<link>http://hungnv.blogsome.com/2007/01/05/p90/#comment-97</link>
		<pubDate>Fri, 05 Jan 2007 07:17:43 +0000</pubDate>
		<guid>http://hungnv.blogsome.com/2007/01/05/p90/#comment-97</guid>
					<description>Capturing Text Inside HTML Tags
$html =PHP Cookbook

Other Chapters
Regular Expressions

Other Recipes
Capturing Text Inside of HTML Tags

Problem
Solution
Discussion
See Also

_END_;

preg_match_all('#&lt;h ([1-6])&gt;(.+?)&lt;/h&gt;#is', $html, $matches);

for ($i = 0, $j = count($matches[0]); $i &lt; $j; $i++) {
  print str_repeat(' ', 2 * ($matches[1][$i] - 1)) . $matches[2][$i] . &quot;\n&quot;;
}
You get:

PHP Cookbook
  Regular Expressions
    Capturing Text Inside of HTML Tags
      Problem
      Solution
      Discussion
      See Also
</description>
		<content:encoded><![CDATA[	<p>Capturing Text Inside HTML Tags<br />
$html =PHP Cookbook</p>
	<p>Other Chapters<br />
Regular Expressions</p>
	<p>Other Recipes<br />
Capturing Text Inside of HTML Tags</p>
	<p>Problem<br />
Solution<br />
Discussion<br />
See Also</p>
	<p>_END_;</p>
	<p>preg_match_all(&#8217;#<h ([1-6])>(.+?)</h>#is&#8217;, $html, $matches);</p>
	<p>for ($i = 0, $j = count($matches[0]); $i < $j; $i++) {<br />
  print str_repeat(&#8217; &#8216;, 2 * ($matches[1][$i] - 1)) . $matches[2][$i] . &#8220;\n&#8221;;<br />
}<br />
You get:</p>
	<p>PHP Cookbook<br />
  Regular Expressions<br />
    Capturing Text Inside of HTML Tags<br />
      Problem<br />
      Solution<br />
      Discussion<br />
      See Also
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: hungnv</title>
		<link>http://hungnv.blogsome.com/2007/01/05/p90/#comment-96</link>
		<pubDate>Fri, 05 Jan 2007 06:52:31 +0000</pubDate>
		<guid>http://hungnv.blogsome.com/2007/01/05/p90/#comment-96</guid>
					<description>Finding All Lines in a File That Match a Pattern
$pattern = &quot;/\bo'reilly\b/i&quot;; // only O'Reilly books
$ora_books = preg_grep($pattern,file('/path/to/your/file.txt'));
</description>
		<content:encoded><![CDATA[	<p>Finding All Lines in a File That Match a Pattern<br />
$pattern = &#8220;/\bo&#8217;reilly\b/i&#8221;; // only O&#8217;Reilly books<br />
$ora_books = preg_grep($pattern,file(&#8217;/path/to/your/file.txt&#8217;));
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: hungnv</title>
		<link>http://hungnv.blogsome.com/2007/01/05/p90/#comment-95</link>
		<pubDate>Fri, 05 Jan 2007 05:08:12 +0000</pubDate>
		<guid>http://hungnv.blogsome.com/2007/01/05/p90/#comment-95</guid>
					<description>/
    ^               # anchor at the beginning
    [^@\s]+         # name is all characters except @ and whitespace
    @               # the @ divides name and domain
    (
        [-a-z0-9]+  # (sub)domains are letters, numbers, and hyphens
        \.          # separated by a period
    )+              # and we can have one or more of them
    (
        [a-z]{2}    # TLDs can be a two-letter alphabetical country code
        |com|net    # or one of 
        |edu|org    # many 
        |gov|mil    # possible
        |int|biz    # three-letter
        |pro        # combinations
        |info|arpa  # or even
        |aero|coop  # a few 
        |name       # four-letter ones
        |museum     # plus one that's six-letters long!
    )
    $               # anchor at the end
/ix                 # and everything is case-insensitive</description>
		<content:encoded><![CDATA[	<p>/<br />
    ^               # anchor at the beginning<br />
    [^@\s]+         # name is all characters except @ and whitespace<br />
    @               # the @ divides name and domain<br />
    (<br />
        [-a-z0-9]+  # (sub)domains are letters, numbers, and hyphens<br />
        \.          # separated by a period<br />
    )+              # and we can have one or more of them<br />
    (<br />
        [a-z]{2}    # TLDs can be a two-letter alphabetical country code<br />
        |com|net    # or one of<br />
        |edu|org    # many<br />
        |gov|mil    # possible<br />
        |int|biz    # three-letter<br />
        |pro        # combinations<br />
        |info|arpa  # or even<br />
        |aero|coop  # a few<br />
        |name       # four-letter ones<br />
        |museum     # plus one that&#8217;s six-letters long!<br />
    )<br />
    $               # anchor at the end<br />
/ix                 # and everything is case-insensitive
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: hungnv</title>
		<link>http://hungnv.blogsome.com/2007/01/05/p90/#comment-94</link>
		<pubDate>Fri, 05 Jan 2007 05:05:16 +0000</pubDate>
		<guid>http://hungnv.blogsome.com/2007/01/05/p90/#comment-94</guid>
					<description>Matching a Valid Email Address
/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i
</description>
		<content:encoded><![CDATA[	<p>Matching a Valid Email Address<br />
/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: hungnv</title>
		<link>http://hungnv.blogsome.com/2007/01/05/p90/#comment-93</link>
		<pubDate>Fri, 05 Jan 2007 05:04:08 +0000</pubDate>
		<guid>http://hungnv.blogsome.com/2007/01/05/p90/#comment-93</guid>
					<description>Matching Words
/\S+/         // everything that isn't whitespace
/[A-Z'-]+/i   // all upper and lowercase letters, apostrophes, and hyphens
</description>
		<content:encoded><![CDATA[	<p>Matching Words<br />
/\S+/         // everything that isn&#8217;t whitespace<br />
/[A-Z&#8217;-]+/i   // all upper and lowercase letters, apostrophes, and hyphens
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
