Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 替换子字符串,除非在预定义的多字符分隔符内_Javascript_Regex_Replace - Fatal编程技术网

Javascript 替换子字符串,除非在预定义的多字符分隔符内

Javascript 替换子字符串,除非在预定义的多字符分隔符内,javascript,regex,replace,Javascript,Regex,Replace,输入字符串如下所示: I am Checking Images whose id is being shown in chapters view as *img*id:14*img* and some other stuff; I want to replace "id" to "identification" except for the instance that appears within the *img* delimiters. 预期结果是: I am Checking Im

输入字符串如下所示:

I am Checking Images whose id is being shown in chapters view as 
*img*id:14*img* and some other stuff; I want to replace "id" to 
"identification" except for the instance that appears within the 
*img* delimiters.
预期结果是:

I am Checking Images whose identification is being shown in chapters 
view as *img*id:14*img* and some other stuff; I want to replace 
"identification" to "identificastionentification" except for the 
instance that appears within the *img* delimiters.
我尝试过的代码:

$scope.This_Page.Dislayed_HTML = $scope.This_Page.Dislayed_HTML.replace('/[^[*]img[*]{"id":([0-9]*)}[*]img[*] ' + $scope.This_Page.Search_String +']/+ig'                            ,
                                                                                '<span style="background-color: rgb(52, 235, 149,0.3);border:dotted 2px green">' + $scope.This_Page.Search_String + '</span>' ) ;

$scope.This_Page.Dislayed_HTML包含我的HTML代码

$scope.This_Page.Search_字符串是我要在html中搜索的字符串

[*]img[*]{id:[0-9]*}[*]img[*]是我希望在搜索中忽略的delimeter


这意味着,如果$scope.This\u Page.Search\u String='img',它将无法在delimeter中找到img。

我猜可能您正在尝试:

常量正则表达式=/\*img\*id:[0-9]*\*img\*id/gm; const str=`我正在检查其id在章节视图中显示为的图像 *img*id:14*img*和其他一些东西;我想将id替换为 标识,但出现在中的实例除外 *img*分隔符。 预期结果是: 我正在检查其标识显示在章节中的图像 查看为*img*id:14*img*和其他内容;我想换一个 识别到识别识别识别,除 出现在*img*分隔符内的实例; const subst=`identification`; const result=str.replaceregex,subst;
console.logresult;根据什么规则将输入字符串更改为输出字符串?到目前为止,您尝试过任何代码吗?如果你试过的话,也把它贴出来anything@CodeManiac,我不确定我是否理解你的问题。在javascript中,我需要将文本中找到的特定字符集的所有实例替换为不同的字符集,除非找到的匹配在两个img标记内。在上面的例子中,我们的想法是将id替换为身份识别,这也创造了有趣的身份识别。我不明白这对我有什么帮助。我想在字符串中搜索关键字img,但我不想在中找到正则表达式中的img。我只是想用一些在html字符串中标记这个关键字的样式来替换搜索字符串的任何accurance。