CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Help with regex

 



SaiyanM
User

Jun 28, 2003, 1:13 PM

Post #1 of 3 (3181 views)
Help with regex Can't Post

Thanks in advance for any help...

If i have a string containing this data

Code
 $string = qq~header.tpl 
<!-- BEGIN SUBBLOCK -->
I'm in subblock
<!-- BEGIN SUBBLOCK1 -->
I'm in subblock1 {{HEADER.SUBBLOCK.SUBBLOCK1.ID1}} {{HEADER.SUBBLOCK.SUBBLOCK1.ID2}}
<!-- END SUBBLOCK1 -->
<!-- END subblock -->
{{ID1}} {{ID2}}~;

how would i use regular expressions to match the text in between <!-- BEGIN [name] --> and <!-- BEGIN [name] -->.

-------------
Whats 2 + 2 x 2?
Its not 8...
(Please Excuse My Dear Aunt Sally)...


Paul
Enthusiast

Jun 28, 2003, 3:55 PM

Post #2 of 3 (3179 views)
Re: [SaiyanM] Help with regex [In reply to] Can't Post


Code
my ($wanted) = $string =~ m|<!-- BEGIN \w+ -->(.+?)<!-- BEGIN \w+ -->|s;



jryan
User

Jul 13, 2003, 8:44 PM

Post #3 of 3 (3161 views)
Re: [Paul] Help with regex [In reply to] Can't Post

That won't work quite right. You'll succeed too early on the inner end block. Try:


Code
$string =~ m|<!-- BEGIN (\w+) -->(.+?)<!-- BEGIN \1 -->|s; 
my $wanted = $2;


Although I highly dislike use of any permutation of .*?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives