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

M

maciekkus

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
 
P

Paul Lalli

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
 
J

John Bokma

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.
 
A

anno4000

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
 
M

maciekkus

Thanks..
That's what I needed :)

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

Regards,
Maciek

Paul Lalli napisal(a):
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top