Php preg_替换特定图案

Php preg_替换特定图案,php,regex,preg-replace,Php,Regex,Preg Replace,我想使用preg_replace将“*@license until*/”替换为“testing” 我怎么做 我的文本如下: /* * @copyright * @license * */ 我希望大家都正确地理解了我的问题。嗯,这不太难。您只需使用s修饰符(PCRE\u DOT\u All,它使正则表达式中的匹配新行): 这应该适合您(注意,未经测试).这里有一个正则表达式,它可以满足您的需要(以多行模式运行) $regex = '#\\*\\s*@license.*?\\*/'

我想使用preg_replace将“
*@license until*/
”替换为“
testing

我怎么做
我的文本如下:

/*
 * @copyright  
 * @license  
 *
 */

我希望大家都正确地理解了我的问题。

嗯,这不太难。您只需使用
s
修饰符(PCRE\u DOT\u All,它使正则表达式中的
匹配新行):


这应该适合您(注意,未经测试).

这里有一个正则表达式,它可以满足您的需要(以多行模式运行)

$regex = '#\\*\\s*@license.*?\\*/'#s';
$string = preg_replace($regex, '*/', $string);
^\s*\*\s*@license(?:(?!\s*\*/)[\s\S])+ /* * @copyright * @license * */ ^ ~ start-of-string \s* ~ any number of white space \* ~ a literal star \s* ~ any number of white space @license ~ the string "@license" (?: ~ non-capturing group (?! ~ negative look ahead (a position not followed by...): \s* ~ any number of white space \* ~ a literal star / ~ a slash ) ~ end lookahead (this makes it stop before the end-of-comment) [\s\S] ~ match any single character )+ ~ end group, repeat as often as possible ^\s*\*\s*@license(?:(?!\s*\*/)[\s\S])+(?=\s*\*/) ↑ positve look ahead for +-----------an end-of-comment marker