JavaScript RegExp didn't recognize negative look behind T.T

i try converting my scripts in ACE containing regexp to negative look behind... specifically this regexp:

/(?<![\w])Doraemon(?![\w])/imgin ruby that works... in JS it doesn't...

i also miss wheren i can use #{} to dynamically change my regexp from ruby...

ex:

/(?<![\w])#{mykey}(?![\w])/imgi'm currently reading some workaround from stackoverflow... hope that i can found some answer from them.

just want to share this for fellow ruby scripter that just recently learning JS...

Ruby is like driving plane using AutoPilot while JS is driving plane using ManualPilot. T.T
I don't think that JavaScript has lookbehind, so you'll have to rewrite your Regex to either use lookahead or parse in multiple steps.
I don't think that JavaScript has lookbehind, so you'll have to rewrite your Regex to either use lookahead or parse in multiple steps.
yeah.. i rewrite it... and fortunately it's not to hard. just need to run some tests.

and apparently it become much much much more simpler regexp that previous version...

/\b(Doraemon)\b/imgjust learn about \b from https://regex101.com/

it's quite useful site... we can test our regexp and there's also some guide in the right side of the site...

although some of them cannot be recognized in Javascript...

another regexp that did not recognized after testing:

\K (reset match)...

in case people use it... Don't... JS don't recognize it.
For look behind you've 2 solution, the first is to use https://www.npmjs.com/package/xregexp-lookbehind which implements lookbehind and also some(if not all) of the new ES 2015 feature, the second is to pass a function as the second parameter of replace, so you can add the lookbehind logic in js and filter the result yourself,

for example in your case it may be something like:

console.log( ['Doraemon', 'fooDoraemon', 'foo Doraemon bar', 'DoraemonLove'].map(function (testString) { return testString.replace(/(\S+)?(doraemon)(\S+)?/gim, function (match, firstCapture, second, thirdCapture) { if (firstCapture || thirdCapture) return match return '-->' + match + '<--' }) }));
I also miss wheren i can use #{} to dynamically change my regexp from ruby...

ex:

/(?<![\w])#{mykey}(?![\w])/img
This is easy to solve, instead of defining the Regular Expression using the regular expression literal syntax (/your regex/) you can use the RegExp constructor directly as 

new RegExp("foo" + myKey + "bar"); EDIT: 

in ES 2015 this will also look better as you could use the template string like 

Code:
new RegExp(`foo${myKey}bar`)

Original thread: https://forums.rpgmakerweb.com/threads/javascript-regexp-didnt-recognize-negative-look-behind-t-t.49311/