更新时间:2022-01-07 21:46:42
据我所知,没有等同于 \Q
和 \E
在AS3 RegExp中。您可以做的与相同的事情 :转义在 RegExp
模式中使用的特殊字符:
As far as I know there is no equivalent to \Q
and \E
in AS3 RegExp. What you can do is the same thing you would in Javascript: escape special characters for use within a RegExp
pattern:
function escapeForRegExp(s:String):String {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
}
// Example:
var s:String = "Some (text) with + special [regex] chars?";
var r:RegExp = new RegExp("^" + escapeForRegExp(s), "g");
// Same as if you wrote the pattern with escaped characters:
/^Some \(text\) with \+ special \[regex\] chars\?/g