Re: How to avoid this greedy match?



News Howardz wrote:
>
The original mail is regarded as a SPAM by Yahoo -- poor regex match :-(.
So I modify the following content and resend it.
================================
Sorry, I make a mistake in the mail below:

$str = "...<script>xxx</script>zzz<script>y222yy</script>...";

I want to match the script section containing "222".
So I wrote regex like this:

/(<script>.*?222.*?<\/script>)/

But it doesn't work.
It still selects the 2 script sections: "<script>xxx</script>zzz<script>y222yy</script>".

Does anyone have an idea how to achieve this?

Is this what you want? It will find the /last/ occurrence of the script
section containing 222.

Rob


use strict;
use warnings;

my $str = "...<script>xxx</script>zzz<script>y222yy</script>...";

$str =~ /.*(<script>.*?222.*?<\/script>)/;

print $1;

**OUTPUT**

<script>y222yy</script>
.



Relevant Pages

  • Re: Please assist on Email form.
    ... >Please be Kind to us newbies... ... >can someone modify this and resend it so I can have the form send to 2 ... Geoff Berrow 0110001001101100010000000110 ...
    (alt.php)
  • Filemaker Pro 3.0, - Preventing data changes while in Browse? a Newbbie
    ... Find and Modify and so on. ... In FileMaker Pro 3.0 I have been unable to ... changing a fields size by mistake etc. ... while in Browse mode you can change data layout, the data, etc. ...
    (comp.databases.filemaker)
  • Re: *p++ = *q++ undefined? why?
    ... (Confession: I very nearly made ... the same mistake.) ... Alright, modify the assumption to: ...
    (comp.lang.c)
  • Re: advice regarding Rigid heddle loom
    ... Mirjam, ... Don't feel badly about the mistake; ... did the same on a previous exchange and to resend it. ... > Jan i got your envelope today and for ME SHAME SHAME i got mine back ...
    (rec.crafts.textiles.yarn)
  • Bracha Shetzivanu on Minhag
    ... I am sorry that I needed to modify the subject title of this topic. ... my previous note I wrote by mistake ... but I dont remember if was of a man or ...
    (soc.culture.jewish.moderated)