Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Is there an alternative to regexp lookbehind in javascript?
- djdolphin
- Scratcher
1000+ posts
Is there an alternative to regexp lookbehind in javascript?
I wrote this javascript code:
It's supposed to replace all newlines not preceded by > with <br>, but it looks like javascript's regexp engine doesn't support lookbehinds. Does anyone know an alternative I could use?
data = data.replace(/(?<!>)\n/g, "<br>");
Last edited by djdolphin (April 1, 2014 01:06:29)
!
- Hardmath123
- Scratcher
1000+ posts
Is there an alternative to regexp lookbehind in javascript?
/[^>]\n/g
- scimonster
- Scratcher
1000+ posts
Is there an alternative to regexp lookbehind in javascript?
Maybe you should ask this on Stack Overflow?
Retired Community Moderator
BTW, i run Google Chrome 41.0.2272.101 on a Linux system - Ubuntu 14.04. NEW: iPad 4th gen. w/retina.
418 I'm a teapot (original - to be read by bored computer geeks)
THE GAME (you just lost)
; THE SEMICOLON LIVES ON IN OUR SIGS
- djdolphin
- Scratcher
1000+ posts
Is there an alternative to regexp lookbehind in javascript?
Thanks, it works great!That doesn't work for initial newlines and doesn't keep the preceding character. You can do something like/[^>]\n/g
replace(/([^>]|^)\n/g, '$1<br>')
!
- Harakou
- Scratcher
1000+ posts
Is there an alternative to regexp lookbehind in javascript?
Closed by request of owner.
- Discussion Forums
- » Advanced Topics
- » Is there an alternative to regexp lookbehind in javascript?