Re: Regular Expression
| From: | Christian Reiniger | Date: | Thu, 19 Apr 2001 09:38:31 +0000 |
| Subject: | Re: Regular Expression | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-49341@lists.php.net to get a copy of this message | ||
On Wednesday 18 April 2001 22:55, you wrote:
> >oops. The expression should read '/\[([^\]]+)\]/'
>
> Thanks all, i used this code and it works:
>
> preg_match("/\[(.+)\]/",$msg_array[$i],$segments);
Note: This won't do what you expect, since the ".+" part will match as
much as possible.
Example: For "This [is a] string [with] multi [brack]ets"
it will match
"is a] string [with] multi [brack"
A better solution would be "/\[(.+?)\]/"
The '?' after the '+' tells it to match as little as possible.
--
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)
/* you are not expected to understand this */
- from the UNIX V6 kernel source