Pregunta

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

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top