Re: How to avoid this greedy match?
- From: news_howardz@xxxxxxxxx (News Howardz)
- Date: Mon, 28 Jan 2008 19:35:57 -0800 (PST)
Sorry, I make a mistake in the mail below:
$str = "...<script>xxx</script>zzz<script>y%%%yy</script>...";
I want to match the script section containing "%%%".
So I wrote regex like this:
/(<script>.*?%%%.*?<\/script>)/
But it doesn't work.
It still selects the 2 script sections: "<script>xxx</script>zzz<script>y%%%yy</script>".
Does anyone have an idea how to achieve this?
Thanks
Howardz
----- Original Message ----
From: News Howardz <news_howardz@xxxxxxxxx>
To: beginners@xxxxxxxx
Sent: Tuesday, January 29, 2008 11:22:41 AM
Subject: 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
--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
.
- Prev by Date: How to avoid this greedy match?
- Next by Date: Re: How to avoid this greedy match?
- Previous by thread: How to avoid this greedy match?
- Next by thread: Re: How to avoid this greedy match?
- Index(es):
Relevant Pages
|
|