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: Beginner:
And more regular expressions ...

 



yaniv_av
Novice

Nov 4, 2002, 2:33 PM

Post #1 of 2 (404 views)
And more regular expressions ... Can't Post

let a string be:
"bla bla <b> abc def </b> bla bla <b> abc ttt </b> bla bla "

I want to create a new string containig all the data between <b> to </b> (include those tags) - and remove all the other characters.
In this case the new string should b:
$new="<b> abc def </b> <b> abc ttt </b>"
How can I do it ?


Paul
Enthusiast

Nov 4, 2002, 2:47 PM

Post #2 of 2 (402 views)
Re: [yaniv_av] And more regular expressions ... [In reply to] Can't Post


Code
my $string = "bla bla <b> abc def </b> bla bla <b> abc ttt </b> bla bla "; 
my $new_string;

$new_string .= " $1 " while ($string =~ m|(<b>.*?</b>)|g);


Or you could just do:


Code
$string =~ s/>.*?</> </g;



(This post was edited by RedRum on Nov 4, 2002, 2:49 PM)

 
 


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

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