regexPatternArgumentManipulator->matchCallArgumentWithRegexPattern() call */ private const THREE_BACKSLASH_FOR_ESCAPE_NEXT_REGEX = '#(?<=[^\\\\])\\\\{2}(?=[^\\\\])#'; /** * @var string * @see https://regex101.com/r/YgVJFp/1 */ private const LEFT_HAND_UNESCAPED_DASH_REGEX = '#(\\[.*?\\\\(w|s|d))-(?!\\])#i'; /** * @var string * @see https://regex101.com/r/TBVme9/9 */ private const RIGHT_HAND_UNESCAPED_DASH_REGEX = '#(?> */ public function getNodeTypes() : array { return [String_::class]; } /** * @param String_ $node */ public function refactor(Node $node) : ?Node { $stringKind = $node->getAttribute(AttributeKey::KIND); if (\in_array($stringKind, [String_::KIND_HEREDOC, String_::KIND_NOWDOC], \true)) { return null; } if (StringUtils::isMatch($node->value, self::THREE_BACKSLASH_FOR_ESCAPE_NEXT_REGEX)) { return null; } $stringValue = $node->value; if (StringUtils::isMatch($stringValue, self::LEFT_HAND_UNESCAPED_DASH_REGEX)) { $node->value = Strings::replace($stringValue, self::LEFT_HAND_UNESCAPED_DASH_REGEX, '$1\\-'); // helped needed to skip re-escaping regular expression $node->setAttribute(AttributeKey::IS_REGULAR_PATTERN, \true); return $node; } if (StringUtils::isMatch($stringValue, self::RIGHT_HAND_UNESCAPED_DASH_REGEX)) { $node->value = Strings::replace($stringValue, self::RIGHT_HAND_UNESCAPED_DASH_REGEX, '\\-$1]'); // helped needed to skip re-escaping regular expression $node->setAttribute(AttributeKey::IS_REGULAR_PATTERN, \true); return $node; } return null; } }