How to avoid this greedy match?



Hi,

I have a trouble when composing a regex.

$str = "...<scirpt>xxx</script>zzz<script>yyy</script>..."

In the above string, "xxx" and "yyy", "zzz" stand for any substring other than "<script>"

I want to pick up "<script>yyy</script>", but each time I get the 2 script sections matched "<scirpt>xxx</script>zzz<script>yyy</script>".

I've tried the following regex:
1) "<script>.*</script>
2) "<script>.*?</script>

How can I avoid the this greedy match?
(I'm using ActivePerl 5.6.1)

Thanks,
Howardz


____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
.



Relevant Pages

  • Re: regex with nots in it
    ... which is what I was trying to avoid. ... It's a perfectly valid suggestion. ... The system I have built checks messages for particular content. ... content is defined in a database, so if I need more than one regex, I need ...
    (comp.lang.perl.misc)
  • Re: Downloading unix text files, convert to non-unix?
    ... to phrase it in the same way you did. ... Regex is foreign to me. ... code to avoid creating instances of that. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to avoid this greedy match?
    ... How to avoid this greedy match? ... I have a trouble when composing a regex. ... Make Yahoo your home page. ...
    (perl.beginners)
  • RE: How to avoid this greedy match?
    ... Regex will always pick up the last occurance of '222'. ... How to avoid this greedy match? ... Make Yahoo your home page. ... Mobile. ...
    (perl.beginners)
  • Re: a regular expression inquiry
    ... after the brackets make it a non greedy match. ... Good explanation, totally correct, but nort the right regex: ... non-greedy should be directly after the selector itself AFAIK. ...
    (comp.lang.php)