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

From: Date: Thu, 31 May 2007 12:26:13 +0000
Subject: Re: Re: Re: Re: preg_match() returns false but no documentation why
Groups: php.general 
Request: Send a blank email to php-general+get-255905@lists.php.net to get a copy of this message
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.
This is what I thought it meant. Your example more than clears it up.
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.)
Very helpful! I still have questions, but a PHP mailing list probably isn't the best place.
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.
That's very confusing to call it 'Full Stop' when it doesn't seem to actually correlate to the regex meaning it identifies, don't you think? Maybe to a Brit or someone who understands Commonwealth English would know (I was aware of what it meant in CE, I just woudn't have imagined to apply it here, since it looks to be descriptive). Kind've like an elephant trainer calling her elephant's trunk a boot. -- Jared Farrish Intermediate Web Developer Denton, Tx Abraham Maslow: "If the only tool you have is a hammer, you tend to see every problem as a nail." $$

« previous php.general (#255905) next »