Re: Re: Space in regex
| From: | Jon Anderson | Date: | Thu, 16 Nov 2006 22:16:22 +0000 |
| Subject: | Re: Re: Space in regex | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244755@lists.php.net to get a copy of this message | ||
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