[plug] Perl regex question

Mark O'Shea mark at musicalstoat.co.uk
Mon Oct 27 09:46:23 WST 2008

On Sun, Oct 26, 2008 at 01:43:09AM +0800, Arie Hol wrote:
> I am trying to run a perl script which needs to apply a regex which will
> be effective over multiple lines.....
> Example :
> <script language="javascript">
>       I want to remove
>       the javascript lines as well as
>       the "script" tags which run over several lines
> </script>
> I have tried many different permutations, including the following :
> $line =~ s/<script.*script>//smi ;
Okay, I'm not sure what you are doing wrong as this expression does work
for the above example.  One problem however that you may have is with
greedy matches if you have more than one script block in your html.
This will remove all the (presumably wanted) text in between the two

To make it ungreedy use:
$line =~ s/<script.*?script>//smig

(note the ? to make it ungreedy and the g to make it remove all
occurrances in the line (the line being the whole file in this case)).


More information about the plug mailing list