Re: Re: Space in regex

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

 



At 11/16/2006 01:56 PM, Dotan Cohen wrote:
$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.


Dotan,

I'm surmising what you really want to do is grab all the characters between [ and | for the first field, and everything from | to ] as the second field. I would therefore identify the first field with:

        [^\]|]
        anything except the close-bracket and the vertical pipe

and the second field with:

        [^\]]
        anything except the close-bracket

Therefore:

        /\[([^\]|]+)\|([^\]]+)\]/

Regards,
Paul
--
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