Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Stripping the contents of Javascript tags

by svsingh (Priest)
on May 27, 2003 at 23:03 UTC ( [id://261127]=note: print w/replies, xml ) Need Help??


in reply to Stripping the contents of Javascript tags

You're probably experiencing greed. This means the .* in the middle of your match will grab everything between the first <script> and last </script> in $foo, including other </script>...<script> combinations.

The following code should give you some ideas. It does assume that there are no other HTML tags between the <script> and </script> tags.

$s = qq(<script>chunk1</script> stuff <Script>chunk2</Script>); while ( $s =~ m|<script>([^<]+)<\/script>|gi ) { print "match: $1\n"; }

Also, I don't know if this was intentional or not, but you're also doing a substitution by starting your expression with an s. That will replace anything you match in $foo with nothing (effectively removing it from the scalar).

I hope this is what you were looking for.

Replies are listed 'Best First'.
Re: Re: Stripping the contents of Javascript tags
by Cody Pendant (Prior) on May 28, 2003 at 00:26 UTC
    It does assume that there are no other HTML tags between the <script> and </script> tags.

    Er, no it doesn't -- it assumes there are no HTML open-brackets inside the script tags, and as they are also the less-than signs, that's a fatally flawed assumption. Any JavaScript for-loop will kill that regex.
    --

    “Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
    M-J D
Re: Re: Stripping the contents of Javascript tags
by sauoq (Abbot) on May 27, 2003 at 23:20 UTC
    This means the .* in the middle of your match. . .

    Uhm... that .* looks an awful lot like a .*? to me. ;-)

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Re: Stripping the contents of Javascript tags
by svsingh (Priest) on May 28, 2003 at 03:26 UTC
    Ack! Sorry about that. I guess a little knowledge really can be dangerous. Thanks for letting me know where I went wrong.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://261127]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-26 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found