Giter Club home page Giter Club logo

Comments (5)

pkvach avatar pkvach commented on June 9, 2024 1

Apologies for intervening, but I noticed that the original Regexp is invalid.
There is an extra opening square bracket in it.
/[^[a-zA-Z0-9_]/

It was probably intended to be like this:
/[^a-zA-Z0-9_]/

So I'm unsure if it's a bug in Rector.

from rector.

gemal avatar gemal commented on June 9, 2024
-$purln = preg_replace("/[^[a-zA-Z0-9_]/", "", "test");
+$purln = preg_replace("/[^\\w/", "", "test");

$purln = preg_replace("/[^\\w/", "", "test");
s not valid

from rector.

TomasVotruba avatar TomasVotruba commented on June 9, 2024

Seems legit. Could you send PR with a fix?

from rector.

samsonasik avatar samsonasik commented on June 9, 2024

@pkvach the original regex is correct, see https://3v4l.org/Y881D and https://regex101.com/r/I47eIK/1 . That's strange, but correct.

from rector.

pkvach avatar pkvach commented on June 9, 2024

@samsonasik
Oh, I see, thank you.
Just noticed it didn't look right. And some Regex validation services are giving an error on it.

And SimplifyRegexPatternRector just replaces the pattern it finds in the original Regex.

private const COMPLEX_PATTERN_TO_SIMPLE = ['[0-9]' => '\\d', '[a-zA-Z0-9_]' => '\\w', '[A-Za-z0-9_]' => '\\w', '[0-9a-zA-Z_]' => '\\w', '[0-9A-Za-z_]' => '\\w', '[\\r\\n\\t\\f\\v ]' => '\\s'];

from rector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.