Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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
Php 忽略<;脚本>-标记,同时用链接替换关键字_Php_Regex_Preg Replace - Fatal编程技术网

Php 忽略<;脚本>-标记,同时用链接替换关键字

Php 忽略<;脚本>-标记,同时用链接替换关键字,php,regex,preg-replace,Php,Regex,Preg Replace,我想用链接替换文本中的关键字。所以我创建了这个preg_替换: $include = preg_replace('/(?!(?:[^<]+>|[^>]+<\/(span)><\/(a|option|h3)>|[^>]+<\/(a|option|h3|h4|h5|textarea|input|script)>))\b('.$key->key_word.')\b/is', '<a href="/'.$lang.'/'.$key-

我想用链接替换文本中的关键字。所以我创建了这个preg_替换:

$include = preg_replace('/(?!(?:[^<]+>|[^>]+<\/(span)><\/(a|option|h3)>|[^>]+<\/(a|option|h3|h4|h5|textarea|input|script)>))\b('.$key->key_word.')\b/is', '<a href="/'.$lang.'/'.$key->key_area.'/'.$key->key_page.'.html" title="'.$key->key_title.'" class="keylink">\\4</a>',$include,$limit,$count);
$include=preg_replace('/(?!(?:[^ |[^>]+|[^>]+)\b('.$key->key_word.)\b/is',''.$include,$limit,$count);
现在有一个问题,这个regexp在JavaScript(…)中工作。我如何更改它来解决这个问题

谢谢您的帮助!

肥皂盒 我们可以设计一个正则表达式来匹配您的具体情况,但是考虑到这是HTML解析,并且您的用例暗示可能存在任意数量的标记,您最好使用DOM或使用类似的产品

然而 考虑以下通用正则表达式的powershell示例。在该示例中,我将迭代任何脚本标记之外的每个匹配文本。从这里,您可以将字符串替换应用于每个匹配的组。应该注意的是,如果在脚本内使用类似于打开或关闭
标签

(?:^ |]*>)(.*)(?)(=that;bla;bla是
让我们拭去旧的emm的灰尘…此时编写的代码可以工作。因此我可以解析给定的内容。但现在我想忽略script和/script之间的内容嘿,你使用哪个程序来获取正则表达式的图表?看起来真不错!:)@Igor:谢谢。我使用了debuggex.com,它比regexper.com更快、更实时。但他们两个都对同一件事感到惊讶。非常方便查看正则表达式的工作原理。谢谢您的提示!:)
$Regex = '(?:^|</script[^>]*>)(.*?)(?=<script\s|$)'
$String = 'i wanna match a string contains<script src=value> is > that; bla ; bla is < this</script> match "bla" '

Write-Host start with 
write-host $String
Write-Host
Write-Host found
$Matches = @()
([regex]"(?i)$Regex").matches($String) | foreach {
    write-host "value at $($_.Groups[1].Index) = '$($_.Groups[1].Value)'"
    } # next match
start with
i wanna match a string contains<script src=value> is > that; bla ; bla is < this</script> match "bla" 

found
value at 0 = 'i wanna match a string contains'
value at 89 = ' match "bla" '