Re: Re: Space in regex

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

 



Dotan Cohen wrote:
I should add more information. This is the entire regex:
$text=preg_replace_callback('/\[([A-Za-z0-9\'.-:underscore:]+)\|([A-Za-z0-9\'.
-:underscore:]+)\]/i' , "findLinks", $text);

This regex should match any pair of square brackets, with two bits of
text between them seperated by a pipe, like these:
[Ety|wife]
[Jarred|brother]
[Ahmed|neighbor]
[Gili and Gush|pets]
[Bill Clinton|horny]

I would expect that the "." would match spaces, but it doesn't. So the
first three examples that I've shown are matched, but the last two are
not. I've even added "\w", "\s", " ", and ":space:" to the regex, but
of course that's not matching, either. What am I doing wrong? Note
that I've been honing my regex skills for the past few days, but I've
not so much experience with them. Thanks in advance to whoever can
help me understand this.
This appears to work for me:

preg_match('/\[([A-Za-z0-9\s\'.-:underscore:]+)\|([A-Za-z0-9\s\'.-:underscore:]+)\]/i','[Test 1|Test 2]',$matches);
print_r($matches);

produces:
Array
(
   [0] => [Test 1|Test 2]
   [1] => Test1
   [2] => Test2
)

Alternately, I would use the following regex: /\[([^\|]+)\|([^\|]+)\]/ which is a little cryptic, but very flexible for what you mention above. It works for me as well...

jon

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