0

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! :)

T_t
  • 375
  • 1
  • 6
  • 12
  • 7
    Don't use regex to parse HTML. Here's why http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – Darin Dimitrov Mar 31 '10 at 11:15

2 Answers2

0

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
  • 56,361
  • 10
  • 99
  • 123
0

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

/[^y]class/
/\bclass/
/class abc/
Victor
  • 9,210
  • 3
  • 26
  • 39