Safari support for lookahead and behind RegExp

Viewed 564

I have the following Regex, which is fine in Chrome FF but safari does like it. I am attempting to identify string that have a \n return without a space surrounding it.

Good: test /n message Bad: test/nmessage

var regex = RegExp("\n(?! )|(?<! )\n");

Can anyone transpose this to better support Safari?

enter image description here

1 Answers

Are you looking for below regex, here $1 will contain the newline that is not surrounded by space on either side.

[^ ](\n)[^ ]

You can use this in javascript like below

var case1 = "firstline\nsecond"; 
var match1=case1.match(/[^ ](\n)[^ ]/g)
if(match1==null) console.log("Has newlines surrounded with space");
else console.log("NO newlines with space");

Related