Re: preg_match

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

 



* John Nichel <john@xxxxxxxxxxxx> :
> Richard Lynch wrote:
> > On Thu, August 18, 2005 2:50 pm, Jon wrote:
> > > preg_match_all("/Charges \s\s+ $total x (.+) /siU", $single,
> > > $from_invoice);
> > 
> > I would recommend using \\s instead of \s -- While \s doesn't have any
> > meaning in PHP strings, so PHP just figures you must have meant \\s
> <snip>
>
> But in perl type regex's, the \s is a space.  Without testing it, I 
> don't think \\s would match what the OP was looking for (I *think* it 
> would match '\s').  However, I don't understand why the OP is looking 
> for a space " ", followed by a space "\s", followed by multiple spaces 
> "\s+"....a \s{1,} would have done all that just fine.

But in double quotes, \ is seen as an escape, and could be interpreted
differently. Probably the better way to do this would be:

$pattern = '/Charges\s+' . $total . ' x ([^\s]*)/si';
preg_match_all($pattern, $single, $from_invoice);

-- 
Matthew Weier O'Phinney
Zend Certified Engineer
http://weierophinney.net/matthew/

-- 
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