Link to home
Start Free TrialLog in
Avatar of AdmiralHorror
AdmiralHorror

asked on

PHP, regex and lazy star

Hello

I need to write a line of code in PHP to remove image tags from a string.

I am trying the following...

echo eregi_replace("<img .*?>", "", "some string <img src=> with images <img src=   >");

...but keep getting the "Warning: eregi_replace(): REG_BADRPT in .../test.php on line ..." errormessage.

If I remove "?" from the regex it doesn't throw an error, but doesn't work as needed either doing a greedy match.

Please help

Thank you
ASKER CERTIFIED SOLUTION
Avatar of Tomeeboy
Tomeeboy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AdmiralHorror
AdmiralHorror

ASKER

Ok, that worked, thank you very much.

However, could you please explain to me the meaning of "/" in front of the "<" and the meaning of "/i"
I think that the front slashes just define where the actual pattern starts/stops... though I'm not 100% sure on that :)  I always put them around a regex pattern for any PHP functions that use a regex pattern.  The "i" makes the pattern case insensitive.