Reputation: 7070
I have a pipe delimited file and want to replace all the occurrences of |N.D.| with | | .
I did this:
$line =~ s/\|N.D.\|/\| \|/g;
but if the line has repeating N.D. like this:
12354|this is test|N.D|N.D|some more text|
it will only replace one. How do I fix it to replace all?
Upvotes: 1
Views: 104
Reputation: 23777
Typically you use a simple positive lookahead for this:
\|N\.D(?=\|)
and substitute it with |
$line =~ s/\|N\.D(?=\|)/\| /g;
That way the trailing |
is not included in the match and the next match will be able to start there.
Upvotes: 2