Reputation: 21
I am trying to remove some garbage js code on 4k+ webpages. The webpages have other js on the page as well so I need to only get rid of the JS with a particular function called clickIE.
I have this one liner working until I introduce the regex...
perl -p -i -e 's|<script(.*)>.*clickie.*?<\/script>|<\!--REMOVED-JS-CODE-->|gixsm' ./*.html
My regex works correctly when tested at http://www.gskinner.com/RegExr/ but fails on the command line...(fails meaning... the regex doesnt match anything)
Upvotes: 0
Views: 1444
Reputation: 37136
For the regex to work, the entire file needs to be slurped in at once.
$ perl -0777 -pi -e 's/your/regex/gix' ./*.html
Upvotes: 3
Reputation: 485
As noted by @Mark the matches should be non-greedy. This seems to work...
perl -i -p -e 's|<script.*?>.*?clickie.*?</script>|<!-- removed -->|gism'
Upvotes: 0