开发者

Html regex leading and trailing words

I have a feeling that I'm really missing something obvious here but I'm looking for a regex that will match the content of a bold tag plus the words immediatly before and after the tags.

So:

"start this string <b>is the text</b> we need end"

would match to

"string &l开发者_如何学Pythont;b>is the text</b> we"

I can get to the tags and their content with <b\s*>(.*?|[^>\s]+)<\/b\s*> but I can't seem to nail down the leading and trailing words.

Any help would be appreciated.


Try this (based on your regex):

/\w+\s*<b\s*>(?:.*?|[^>\s]+)<\/b\s*>\s*\w+/

See it on Rubular regex tester

But perhaps this would be better:

/\w+\s*<b\s*>.*?<\/b\s*>\s*\w+/

See it on Rubular regex tester

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜