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
  • 40,237
  • 31
  • 123
  • 190
stack
  • 563
  • 9
  • 19
  • 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
  • 195,511
  • 20
  • 184
  • 225
0

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

Check this demo.

Ωmega
  • 40,237
  • 31
  • 123
  • 190