Re: Re: Space in regex
| From: | Dotan Cohen | Date: | Thu, 16 Nov 2006 23:19:36 +0000 |
| Subject: | Re: Re: Space in regex | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244758@lists.php.net to get a copy of this message | ||
On 17/11/06, Paul Novitski <paul@juniperwebcraft.com> 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: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/[^\]|] anything except the close-bracket and the vertical pipeand the second field with:[^\]] anything except the close-bracketTherefore:/\[([^\]|]+)\|([^\]]+)\]/Regards, Paul