Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以在 javascript 中附加正则表达式文字和字符串文字吗?像这样:
var str = "iam 91 old"; var query = 'old'; var reg = /(\d+\s + query +)/; alert(reg.exec(str)[1]);
这条鳕鱼将是错误的。
不要使用文字。
使用RegExp构造函数:
var reg = new RegExp("(\\d+\\s" + query + ")");