Re: Re: Re: Re: preg_match() returns false but no documentation why

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Jared,

At 5/30/2007 06:00 PM, Jared Farrish wrote:
Read the manual:

All due respect, I did read it. It's just... a little dense and not
practically descriptive.

Sorry, I didn't mean to be disrespectful, I thought your question was more elementary than it was. There are, though, a ton of regular expression resources on the net. Google Is Your Friend. I just got a million hits on 'regular expression tutorial.'


Maybe it's more practical to ask, "When is it practical to use it?"

It matches anything, so I assume that means you can use it to match, say, a
paragraph that you can't predict or match against? One that you're looking
for a pattern match on one or either end?

Well, sure. It often appears as .* meaning "none or any number of any characters." Use it when you honestly don't care what it matches.

Say you want to find out if the word "frog" occus in a text followed by the word "dog." You could match on:

        /\bfrog\b(.*\b)?dog\b/i

/       pattern delimiter
\b      word boundary
frog    1st word
\b      word boundary

(       begin subpattern
.*      zero or any characters
\b      word boundary
)       end subpattern
?       zero or one instance of the preceding subpattern

dog     2nd word
\b      word boundary
/       pattern delimiter
i       case-insensitive

This guarantees that both words are bounded by word boundaries and allows any number of any characters to occur between them. (There's sort of an implicit .* before and after the pattern. Because I haven't used ^ and $ to define the beginning and end of the text, regex looks for my pattern anywhere in the text.)


And why is it called full stop?

That's what the 'period' is called in British English.
http://google.ca/search?q=define%3Afull+stop

In English syntax "period" and "full stop" are synonymous, and the RegEx manual is throwing "dot" into the same bag.

Regards,

Paul
__________________________

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux