Home: Perl Programming Help: Regular Expressions:
correct my regex please?



demon01
Novice

May 17, 2008, 9:27 AM


Views: 9457
correct my regex please?

$course_name has HTML tags that I need to removes. There are several and not all have closing tags.

This is what I came up with but I was wondering if there was a to make it all one regex expression.

$course_name=~ s/<(\w+)>/ /;
$course_name=~ s/<(\/\w.*)>/ /;
$course_name=~ s/<(\w.*)>/ /;

I am still not clear on how to group expressions.


KevinR
Veteran


May 18, 2008, 8:25 AM


Views: 9423
Re: [demon01] correct my regex please?


Code
s/<\/?[^>]+>//g;

-------------------------------------------------


KevinR
Veteran


May 18, 2008, 9:12 AM


Views: 9420
Re: [demon01] correct my regex please?


Code
s/    <- beginning of regexp 

<\/? <- search for < followed by none or one /

[^>]+ <- one or more of any characters except >

> <- search for >

//g <- replace the above pattern with nothing. The 'g' finds and replaces all occurances of the pattern in the string



No need for a donation
-------------------------------------------------


(This post was edited by KevinR on May 18, 2008, 9:18 AM)


demon01
Novice

May 18, 2008, 10:06 AM


Views: 9412
Re: [KevinR] correct my regex please?

Thanks Kevin, offer stills stands.



Not sure how my PM got double posted.