[nycphp-talk] Help with regex
Analysis & Solutions
danielc at analysisandsolutions.com
Fri May 16 12:28:09 EDT 2003
Hi Nestor:
On Fri, May 16, 2003 at 11:27:23AM -0400, Nestor Florez wrote:
> <td width="49">205</td>
>
> $line = ereg_replace(".*>", "", $line);
As you probably realized, this is too greedy. The reason is because ".*"
is matching ANY character, including ">" so it goes through the whole line
until it gets to the final ">" This can be tweaked a tad so all
characters except ">" are
$line = ereg_replace('^[^>]+>', '', $line);
Also notice the anchoring of the expression to the start of the line to
avoid the expression repeating it's actions on subsequent >'s, and the use
of single quotes since no variables are in the expressions.
> $line = ereg_replace(".*?>", "", $line);
You're on the right track, but "?" is for preg expressions. So, another
option is converting it to a preg function:
$line = preg_replace('/^.*?>/', '', $line);
Enjoy,
--Dan
--
FREE scripts that make web and database programming easier
http://www.analysisandsolutions.com/software/
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7th Ave #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409
More information about the talk
mailing list