0

I want to use a plain string as the regex expression parameter, and execute this regex against a string with some special symbol(+= ... etc) Here I have written a demo code, and a fiddle here:

var s = 'plain string plus some other symbol + other string '
var re = 'plain string plus some other symbol + '
var reg = new RegExp(re,'gu')
var myArray;
myArray = reg.exec(s)
console.log(myArray) // here does not work, return null
var s = 'plain string plus some other symbol and other string '
var re = 'plain string plus some other symbol and '
var reg = new RegExp(re,'gu')
var myArray;
myArray = reg.exec(s)
console.log(myArray) //here works: return 'plain string plus some other    symbol and '

How to make javascript regex.exec recognize the special symbol += as a plain string and match it?

Xorifelse
  • 7,878
  • 1
  • 27
  • 38
kidsit
  • 287
  • 3
  • 22

0 Answers0