diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escape_content_delimiter_in_pattern.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escape_content_delimiter_in_pattern.php.inc new file mode 100644 index 000000000000..856e1d249442 --- /dev/null +++ b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escape_content_delimiter_in_pattern.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector.php b/rules/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector.php index e037d2f8a086..0fb9acc68ffc 100644 --- a/rules/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector.php +++ b/rules/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector.php @@ -168,6 +168,8 @@ private function refactorArgument(Arg $arg): void $string->value = Strings::replace($value, self::INNER_REGEX, function (array $match): string { $innerPattern = $match['content']; + $innerPattern = str_replace($this->delimiter, '\\' . $this->delimiter, $innerPattern); + // change delimiter if (strlen($innerPattern) > 2 && $innerPattern[0] === $innerPattern[strlen($innerPattern) - 1]) { $innerPattern[0] = $this->delimiter;