[英]find . character in regular expression problems
我無法在正則表達式中替換“ joe.
”之類的東西。 這是代碼
var objects = new Array("joe","sam");
code = "joe.id was here so was sam.id";
for(i = 0; i < objects.length; i++) {
re = new RegExp(objects[i]+"\.", "g");
code = code.replace(re, "stan ");
}
我試過\\.
, \\\\.
, \\\\\\.
,但這些似乎都不起作用。
您的代碼與"\\\\."
完美配合"\\\\."
var objects = new Array("joe","sam");
code = "joe.id was here so was sam.id";
for(i = 0; i < objects.length; i++) {
re = new RegExp(objects[i]+"\\.", "g");
code = code.replace(re, "stan ");
}
"\\\\."
創建字符串\\.
,符合要求。
您可以使用[.]
而不是轉義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.