ici est une expression rationnelle qui fait ce que vous voulez (l'exécuter en mode multi-ligne)
^\s*\*\s*@license(?:(?!\s*\*/)[\s\S])+
il correspond à la partie qui est barré:
/*
* @copyright
* @license
*
*/
Explication:
^ ~ 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
Notez que le regex doit encore être échappé selon les règles de chaîne PHP et selon preg_replace()
règles.
EDIT: Si vous avez envie - de faire absolument sûr qu'il ya vraiment une fin de commentaire marqueur suivant le texte correspondant, l'expression régulière peut être étendu comme celui-ci:
^\s*\*\s*@license(?:(?!\s*\*/)[\s\S])+(?=\s*\*/)
↑ positve look ahead for
+-----------an end-of-comment marker
très utile façon d'expliquer la syntaxe regex, thx –