Re: Help with regular expressions
| From: | DL Neil | Date: | Sat, 26 Jan 2002 16:57:33 +0000 |
| Subject: | Re: Help with regular expressions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-82133@lists.php.net to get a copy of this message | ||
Daniel,
> Hi! I´m new to regular expressions, and it seems to be an art to make it
> work as expected.
>
> I´m trying to remove all "single-line" comments from an string - that´s
> everything after "//" to the end of a line. I expected that this would do
> the job: ereg_replace("//[[:alnum:]]*\n","",$string), but it didn´t work.
>
> Any tips?
RegEx can be expensive. Always ask "do I need one?"
In this case, use a string find to locate the // and the following \n (or whatever marks the end of
line on
your/supported OpSys), then substring or string replace.
If would be quite interesting to see a performance comparison on this - if you've got time...
=dn
PS if you were working with alpha-text and had to consider upper and lower case, then things might
sound very
different!