[英]js regexp variable parenthesis
So I have a function that receives an argument (named c
), then I create a regular expression like so: regC = new RegExp(c,'gi')
. 因此,我有一个函数接收参数(名为c
),然后创建一个正则表达式,如下所示: regC = new RegExp(c,'gi')
。 Now this works fine for most characters, but my function can also receive a (
or other paretheses. This cases create an error. I tried this: regC = '/['+c+']/gi'
, but it didn't work 现在,这对于大多数字符都可以正常工作,但是我的函数也可以接收(
或其他paretheses。这种情况下会产生错误。我尝试了此操作: regC = '/['+c+']/gi'
,但没有用
Pass the character set '['+c+']'
to RegExp
functions as 将字符集'['+c+']'
传递给RegExp
函数,如下所示:
regC = new RegExp('['+c+']','gi');
Because 因为
regC = '/['+c+']/gi'
Makes a string 做一个字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.