[thelist] REGEX Problem
Carl Meyer
cjmeyer at npcc.net
Wed May 12 17:31:47 CDT 2004
hi Alexis,
On Wed, 12 May 2004, The Lists wrote:
> I have the following line of text, of which I want to get rid of
> everything between and including the brackets.
>
> C-FDRK (A320-211 84 204 AC) 2024 20040506 AC0632 (CYUL-CYHZ)
> ereg_replace("\(.*.\) ","",$message[$i])
>
> Which produces:
>
> C-FDRK 2024 20040506 AC0632 (CYUL-CYHZ)
Use preg_replace - it's faster and better than ereg_replace. Here's your
code:
preg_replace("/\(.*?.\)/", "", $str);
The .*? is a non-greedy wildcard, making the space at the end of your regex
unnecessary, thus solving the end-of-line problem. If for some reason you
can't use preg_replace, ereg_replace doesn't support the .*? syntax.
Instead, you can use:
ereg_replace("\([^\)]*.\)", "", $str);
HTH,
Carl
More information about the thelist
mailing list