I'm having a file, with some content, let's say, press y ='Accept' press y ='hey there'

i need to clear all those patterns with y ='something' ? How to do this using perl ?

In the past, I've tried like

foreach(@lines) {
     $_ =~ s/y='*/ /g;

but this is only replacing a single character after the pattern

I'm not sure about the following pattern or length of the following pattern, but need to replace every thing after the 'y= pattern ? provided y= is not at the starting of the line

1 Answers

Community On Best Solutions

This is what I've tried and is working for me


my $str = "press y ='Accept' press y ='hey there'";
$str =~s/y ='.*?'/ /g;
print $str;

What this does is matches from "y='" to first matching single quote after that i.e Its a non greedy matching regex.