Skip to content

Incorrect behavior of SimplifyRegexPatternRector #9395

@marcreichel

Description

@marcreichel

Bug Report

The SimplifyRegexPatternRector produces broken regular expressions where the escape character is missing.

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/e0420e6c-273f-42d1-a8e5-3a9020bda3cb

<?php

final class DemoFile
{
    public function run(string $param)
    {
        return preg_match('/^[0-9]+$/', $param);
    }
}

Responsible rules

  • SimplifyRegexPatternRector

Expected Behavior

The escape character should be added: '/^\d+$/' instead of '/^d+$/'.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions