I was wondering if there was a way to use Regular expressions to remove n occurrences of characters right before n matches of [removebefore]
Might be unclear, but an example explains everything:
This is a teststring[removebefore][removebefore][removebefore]. blablabla[removebefore][removebefore]
should be changed into
This is a teststr. blablab
Of course this can be done by matching and replacing /.\[removebefore\]/ a dozen of times, but is there a way to do this in one regexp?
EDIT:
I was trying to do this in PHP. And indeed I am searching for a regular expression that matches [anychar]{n}\[removebefore\]{n} where n is the number of removebefore’s.
One possible solution using
perlRegular expression:
Test:
Content of script.pl:
Running script:
And result: