Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > [regexp] matching word, but not beetween...

Reply
Thread Tools

[regexp] matching word, but not beetween...

 
 
maciekkus@gmail.com
Guest
Posts: n/a
 
      08-31-2006
Hello,

How can I use regular expressions to match:

"this is <b>bold and big</b> and this is not bold and big"

I would like regexp to match "bold and big" sentence but not when
inside <b> tag.

Any help?

Regards
Maciek

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      09-01-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> How can I use regular expressions to match:
>
> "this is <b>bold and big</b> and this is not bold and big"
>
> I would like regexp to match "bold and big" sentence but not when
> inside <b> tag.
>
> Any help?


Take a look at
perldoc perlre
and search for "lookahead" and "lookbehind"

[untested]
m#(?<!<b>)bold and big(?!</b>)#;

Paul Lalli

 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      09-01-2006
(E-Mail Removed) wrote:

> Hello,
>
> How can I use regular expressions to match:
>
> "this is <b>bold and big</b> and this is not bold and big"
>
> I would like regexp to match "bold and big" sentence but not when
> inside <b> tag.


If you're processing HTML you might safe yourself a lot of trouble using
modules that could handle HTML. For example, parse the HTML into a tree
using HTML::TreeBuilder and next deleting all b elements might safe you a
lot of trouble.

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/
 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      09-01-2006
<(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Hello,
>
> How can I use regular expressions to match:
>
> "this is <b>bold and big</b> and this is not bold and big"
>
> I would like regexp to match "bold and big" sentence but not when
> inside <b> tag.


Take a look at the FAQ: "How can I split a [character] delimited string
except when inside [character]?". It's about splitting, not matching
but the problems are related.

Anno
 
Reply With Quote
 
maciekkus@gmail.com
Guest
Posts: n/a
 
      09-01-2006
Thanks..
That's what I needed

This worked for me:
(?<!<b>)(bold and big)(?!<\/b>)

Regards,
Maciek

Paul Lalli napisal(a):
> (E-Mail Removed) wrote:
> > How can I use regular expressions to match:
> >
> > "this is <b>bold and big</b> and this is not bold and big"
> >
> > I would like regexp to match "bold and big" sentence but not when
> > inside <b> tag.
> >
> > Any help?

>
> Take a look at
> perldoc perlre
> and search for "lookahead" and "lookbehind"
>
> [untested]
> m#(?<!<b>)bold and big(?!</b>)#;
>
> Paul Lalli


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Pattern matching. Matching multiple lines from while reading from a file. Bobby Chamness Perl Misc 2 05-03-2007 06:02 PM
"'If' must end with a matching 'End If'." <-- BUT IT DOES!! WHY DOESN'TTHE DAMN SERVER SEE IT??? Neo Geshel ASP .Net 2 08-18-2004 01:37 PM
matching the network segment but can't work :-( Facco Eloelo Perl Misc 2 07-30-2004 12:21 PM
Pattern matching : not matching problem Marc Bissonnette Perl Misc 9 01-13-2004 05:52 PM



Advertisments