I'm scripting a conversion from Fortran 77 to Fortran 90, and trying to use PERL REGEX to substitute every ! with a ~ if found within quotes.
THIS> 'Hello !!!! Hello !!!!' becomes> 'Hello ~~~~ Hello ~~~~'
THIS> 'Hello' !!!! 'Hello !!!!' becomes> 'Hello' !!!! 'Hello ~~~~'
I can't figure out how to use transliteration cause it has to be only when in quotes The best I've been able to do is:
perl -pi -e "s/('.*?)\!+(.*')/\1~\2/g" File.txt
But this replaces 4 !s with 1 ~ and doesn't even change the second set of !s
THIS> 'Hello !!!! Hello !!!!' becomes> 'Hello ~ Hello !!!!'
THIS> 'Hello' !!!! 'Hello !!!!' becomes> 'Hello' !!!! 'Hello ~'
Without the + after the \! it replaces just the first ! anyway so you get 'Hello ~!!!'
I can't seem to be able to count each ! and replace it one for one with a ~. And I thought the Global /g would get both sets of !s but no.
Any thoughts?