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.
我有一个字符串:
var str = "str is str, 12str345 and ABCstrDEF";
我想捕获str除ABCstrDEF(str被字母字符包围)之外的所有内容
str
ABCstrDEF
是否可以使用正则表达式限制字母?
一起去
RegExp.quote = function(str) { return (str + '').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); }; var re = new RegExp("/\b[^a-zA-Z]*?" + RegExp.quote(str) + "[^a-zA-Z]*?\b/g"); alert(input.match(re));