I need to try and strip out lines in a text file that match a pattern something like this:
anything SEARCHTEXT;anything;anything
where SEARCHTEXT will always be a static value and each line ends with a line break. Any chance someone could help with the regext for this please? Or give me some ideas on where to start (been to many years since I looked at regex).
I am planning on using PHP’s preg_replace() for this.
Thanks.
This solution removes all lines in
$textwhich contain the sub-stringSEARCHTEXT:My benchmark tests indicate that this solution is more than 10 times faster than
'/\n?.*SEARCHTEXT.*$/m'(and this one correctly handles the case where the first line matches and the second one doesn’t).