/*<;需要PHP正则表达式帮助##&燃气轮机</##&燃气轮机*/

/*<;需要PHP正则表达式帮助##&燃气轮机</##&燃气轮机*/,php,regex,Php,Regex,我正在努力与正则表达式,但无法让它工作。 我已经尝试过: , $text=preg\u replace(“%/\*(?:(?!\*/)*\*/%s”,“new”,“$text”); 但什么都不管用。 我的输入字符串是: $input = "something /*<##>old or something else</##>*/ something other"; $input=“something/*old or something*/other something”

我正在努力与正则表达式,但无法让它工作。 我已经尝试过: ,

$text=preg\u replace(“%/\*(?:(?!\*/)*\*/%s”,“new”,“$text”);
但什么都不管用。 我的输入字符串是:

$input = "something /*<##>old or something else</##>*/ something other";
$input=“something/*old or something*/other something”;
预期结果是:

something /*<##>new</##>*/ something other
something/*new*/其他东西

我看到这里指出的两个问题,您没有捕获组来替换替换替换调用中的分隔标记,并且您的负前瞻语法缺少一个

或考虑使用LoukSkices组合来进行此操作而不捕获组。

$text = preg_replace('%/\*<##>\K.*?(?=</##>\*/)%s', 'new', $text);
$text=preg\u replace('%/\*\K.*(?=\*/)%s','new',$text);

我看到这里指出的两个问题,您没有捕获组来替换替换替换调用中的分隔标记,并且您的负前瞻语法缺少一个

或考虑使用LoukSkices组合来进行此操作而不捕获组。

$text = preg_replace('%/\*<##>\K.*?(?=</##>\*/)%s', 'new', $text);
$text=preg\u replace('%/\*\K.*(?=\*/)%s','new',$text);

我看到这里指出的两个问题,您没有捕获组来替换替换替换调用中的分隔标记,并且您的负前瞻语法缺少一个

或考虑使用LoukSkices组合来进行此操作而不捕获组。

$text = preg_replace('%/\*<##>\K.*?(?=</##>\*/)%s', 'new', $text);
$text=preg\u replace('%/\*\K.*(?=\*/)%s','new',$text);

我看到这里指出的两个问题,您没有捕获组来替换替换替换调用中的分隔标记,并且您的负前瞻语法缺少一个

或考虑使用LoukSkices组合来进行此操作而不捕获组。

$text = preg_replace('%/\*<##>\K.*?(?=</##>\*/)%s', 'new', $text);
$text=preg\u replace('%/\*\K.*(?=\*/)%s','new',$text);
已测试:

$input = "something /*<##>old or something else</##>*/ something other";

echo preg_replace('%(/\*<##>)(.*)(</##>\*/)%', '$1new$3', $input);
$input=“something/*old or something*/other something”;
echo preg_replace(“%(/\*)(.*)(\*/)%”、“$1新$3”、$input);
已测试:

$input = "something /*<##>old or something else</##>*/ something other";

echo preg_replace('%(/\*<##>)(.*)(</##>\*/)%', '$1new$3', $input);
$input=“something/*old or something*/other something”;
echo preg_replace(“%(/\*)(.*)(\*/)%”、“$1新$3”、$input);
已测试:

$input = "something /*<##>old or something else</##>*/ something other";

echo preg_replace('%(/\*<##>)(.*)(</##>\*/)%', '$1new$3', $input);
$input=“something/*old or something*/other something”;
echo preg_replace(“%(/\*)(.*)(\*/)%”、“$1新$3”、$input);
已测试:

$input = "something /*<##>old or something else</##>*/ something other";

echo preg_replace('%(/\*<##>)(.*)(</##>\*/)%', '$1new$3', $input);
$input=“something/*old or something*/other something”;
echo preg_replace(“%(/\*)(.*)(\*/)%”、“$1新$3”、$input);

您没有前置掩码的量词
(.)
匹配所有。因此,它只接受您的评论中的一个字符串。另外,仅替换为
new
不会重新实例化
/*
注释标记。您没有前置掩码
(.)
匹配所有标记的量词。因此,它只接受您的评论中的一个字符串。另外,仅替换为
new
不会重新实例化
/*
注释标记。您没有前置掩码
(.)
匹配所有标记的量词。因此,它只接受您的评论中的一个字符串。另外,仅替换为
new
不会重新实例化
/*
注释标记。您没有前置掩码
(.)
匹配所有标记的量词。因此,它只接受您的评论中的一个字符串。另外,仅用
新的
替换不会重新实例化
/*
注释标记。