开发者

a simple problem about RegExp in Javascript

I have a text:

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

and i have a pattern: class now, i want to f开发者_运维技巧ind the word "class" before "abc" but not in the <font class="myclass"> ,how could i do with RegExp in javascript? Thanks! :)


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.


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜