1

I want to parse text like this

<! this is inside a token > text outside the token <! more inside > more outside

and I want to capture all the tokens and replace them with <span>...</span> tags.

For instance

<! this is inside a token >

should get replaced with

<span> this is inside a token </span>

I tried regex /<!(.+)>/ but it just captures the whole string.

Ωmega
  • 42,614
  • 34
  • 134
  • 203
stack
  • 613
  • 10
  • 20
  • See also the answer to this question: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Richard Close Oct 05 '12 at 21:09

2 Answers2

1

This will work

/<!([^>]+)>/
epascarello
  • 204,599
  • 20
  • 195
  • 236
0

Replace <!([^>]*)> with <span>$1</span>

Check this demo.

Ωmega
  • 42,614
  • 34
  • 134
  • 203