-1

my sample text is :

'<div class="emoji-icons emoji-smile" e-type="smile" style="display:inline-block;" contenteditable="false"></div> is <div class="emoji-icons emoji-grinning" e-type="grinning" style="display:inline-block;" contenteditable="false"></div> very time.'

replace command is :

text.replace(/<div class="emoji-icons (?:.*)" e-type="([a-z]*)"[^>]+><\/div>/ig, '$1')

i want replace all div tag with e-type attribute value. result must be "smile is grinning vary time."

but this regex not work on all matched and work on last matches.

Any ideas or suggestions?

mrlayeghi
  • 113
  • 8
  • 6
    *"Any ideas or suggestions?"* Yes. [**Don't use regular expressions to manipulate HTML.**](http://stackoverflow.com/a/1732454/157247) – T.J. Crowder Sep 23 '15 at 06:18

1 Answers1

1

You need to replace (?:.*)" with (?:.*?)" , also there is no need for () so just use .*?"

var text = '<div class="emoji-icons emoji-smile" e-type="smile" style="display:inline-block;" contenteditable="false"></div> is <div class="emoji-icons emoji-grinning" e-type="grinning" style="display:inline-block;" contenteditable="false"></div> very time.';

text = text.replace(/<div class="emoji-icons.*?" e-type="([a-z]*)"[^>]+><\/div>/ig, '$1')

document.write(text);

.*? : Between zero and unlimited times, as few times as possible

Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188