I have a String from a tabel innerHTML where i need to remove all img tags using replace
my Regex removes everthing after the first img tag my code at JSFiddle here
Asked
Active
Viewed 1.0k times
5

Zion
- 723
- 3
- 7
- 24
-
Do post what you have tried. – nu11p01n73R Aug 17 '15 at 08:46
-
1If you're getting this string from a table's `.innerHTML` property anyway - it's much better if you do this removal using DOM methods instead - don't try to do it with regex. – Dal Hundal Aug 17 '15 at 08:48
-
why is it better with dom? – Zion Aug 17 '15 at 08:49
-
3because [regex is bad for parsing html](http://stackoverflow.com/a/1732454/3702797) (except few rare cases) – Kaiido Aug 17 '15 at 08:50
-
you're performing an operation on a DOM string, why wouldn't use DOM methods - plus regex sux at HTML – Jaromanda X Aug 17 '15 at 08:51
1 Answers
14

nu11p01n73R
- 26,397
- 3
- 39
- 52
-
4Doing this kind of thing with regex is not reliable. For example, this would trip up on something like `
` – Dal Hundal Aug 17 '15 at 08:50
-
@DalHundal I agree. I was just pointing out why *Regex removes everthing after the first img tag* – nu11p01n73R Aug 17 '15 at 08:52