tags:

views:

38

answers:

2

I have a text:

 <font class="myclass">class abc</font> 

and i have a pattern: class now, i want to find the word "class" before "abc" but not in the <font class="myclass"> ,how could i do with RegExp in javascript? Thanks! :)

A: 

Darin's comment is spot on -- don't use RegEx to parse HTML.

If, however, you have a very narrow requirement to find the word "class" immediately following a >, here's your pattern:

>class

There is a space at the end. If you need to capture "class" for replacement, surround it with parentheses ( ), then use the capture group \1.

This is not terribly robust, but is a start and is only applicable for a very narrow search requirement, not for any more involved parsing.

Jay
A: 

Sermons aside, it depends on what you can expect for sure, you can try with:

/[^y]class/
/\bclass/
/class abc/
Victor