Re: Re: Space in regex

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

 



On 17/11/06, Paul Novitski <paul@xxxxxxxxxxxxxxxxxxx> wrote:
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


Thanks, Paul. I've been refining my methods, and I think it's better
(for me) to just match everything between [ and ], including spaces,
underscores, apostrophies, and pipes. I'll explode on the pipe inside
the function.

So I thought that a simple "/\[([.]+)\]/i" should do it. This is the line:
$text=preg_replace_callback('/\[([.]+)\]/i' , "findLinks", $text);
This is what it is doing:
1) on "[~~]" where ~~ does not include spaces nor pipes: The function
replaces "[~~]" with "".
2) on "[~~]" where ~~ includes a pipe, but no space: The function does
not replace anything.
3) on "[~~]" where ~~ includes a space, but no pipe: The function does
not do what I intend it to do, and I am unable to figure out exactly
what it is doing.
3) on "[~~]" where ~~ includes a space and a pipe: The function does
not replace anything.

However, this function:
$text=preg_replace_callback('/\[([A-Za-z0-9\|\'.-:underscore:]+)\]/i'
, "findLinks", $text);
Does what I want it to when there is no space, regardless of whether
or not there is a pipe. It does not replace anything if there is a
space.

Dotan Cohen

http://what-is-what.com/
http://gmail-com.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