Re: How to avoid this greedy match?
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Tue, 29 Jan 2008 14:02:48 +0000
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>
.
- References:
- Re: How to avoid this greedy match?
- From: News Howardz
- Re: How to avoid this greedy match?
- Prev by Date: Re: print records that match regexp
- Next by Date: groups of values from an array
- Previous by thread: Re: How to avoid this greedy match?
- Next by thread: Pseudo-hashes are deprecated
- Index(es):
Relevant Pages
|
|