In an input string we can have multiple occurrences of some specific keywords.
Is there a way we can remove all the lines including and in-between those keywords?
For below example, we have to look for the keyword '#end and traverse upto the line it first finds ); and delete all the lines [including lines which contains '#end and );]
Input ::
PD12"You have completed the survey. Thank you for your time."
info;
);
'#end
PR3"You have completed the survey. Thank you for your time."
info;
);
'#end
SD7"You have completed the survey. Thank you for your time."
info;
);
'#end
Output ::
PD12"You have completed the survey. Thank you for your time."
info;
PR3"You have completed the survey. Thank you for your time."
info;
SD7"You have completed the survey. Thank you for your time."
info;
@ptrobot … Thanks for your quick response.
With the regex you shared, it is working fine when we have the exact input.
But in-case there is another ); in the previous line, it is selecting that line also (Please refer to the attached snap).
Will you be able to modify this regex which only select up-to 1st occurrence of ); when it’s start traversing upwards from '#end ?
Here, we have total 3 occurrences of '#end.
Here what we need is -
Whenever it will find the keyword '#end, it will start traversing upwards till it finds ); [need to consider only upto 1st occurrence of );] and delete all the lines [including lines which contains '#end and );].
With the updated regex, it is working fine for 3rd occurrence, but for 1st & 2nd one it is not selecting anything…
Please let me know if I am still unable to clarify the requirements
Really appreciate the help you are providing here @ptrobot
Thanks for the explanation but Regex can’t find '#end and go up. What it does is to find ); and then go down until it finds '#end. If we don’t want xx in between we need to use (?!xx) to tell it not to match xx.