Git Product home page Git Product logo

Hello, I am trying to use regexp-example but I have an irregular expression and it says that the gem is not compatible with looking back and looking forward, can you help me? is there any solution or do I have to modify the regex? about regexp-examples HOT 4 CLOSED

tom-lord avatar tom-lord commented on May 31, 2024
Hello, I am trying to use regexp-example but I have an irregular expression and it says that the gem is not compatible with looking back and looking forward, can you help me? is there any solution or do I have to modify the regex?

from regexp-examples.

Comments (4)

tom-lord avatar tom-lord commented on May 31, 2024 1

So it would be possible to re-structure that regex to make it genuinely regular - and therefore leverage this gem - but it's up to you whether you'd like to restructure it...

This:

(?!0{2})[0-9]{2}

Could be written as:

([0-9][1-9]|[1-9][0-9])

And this:

[TV] ((?<=[T])[X-Z]|(?<=[V])[A-HJ-NPR-Z])

(Won't actually work as you expect, since there's an extra space, but) could be written as:

(T[X-Z]|V[A-HJ-NPR-Z])

...and voila, the regex is regular!

Final result:

/^([0-9][1-9]|[1-9][0-9]) (T[X-Z]|V[A-HJ-NPR-Z])[1-9][A-HJ-NPR-Z]$/.random_example
# => "50 VV6R"

Magic 😄

from regexp-examples.

tom-lord avatar tom-lord commented on May 31, 2024

Hi @anderstroker. It's hard to give advice without seeing a concrete example of your use case. Could you share it?

As I've stated in the README, and explained in more detail in a blog post, "irregular" aspects of regex (such as lookarounds) cannot be supported by this library's algorithm.

Perhaps there is a different way to construct the regex, without lookarounds; or perhaps this library isn't a good fit for your problem.

from regexp-examples.

anderstroker avatar anderstroker commented on May 31, 2024

Oh shure, let me show you, I am building a project that through the license plates validate to which entity they belong, type of vehicle, and other things, I use the gem to give me all the combinations of the regex, I built an example for trailers.
(?!0{2}) this ignore 00,just 01 to 99
[TV] ((?<=[T])[X-Z]|(?<=[V])[A-HJ-NPR-Z]) this depending behing character

^(?!0{2})[0-9]{2} [TV] ((?<=[T])[X-Z]|(?<=[V])[A-HJ-NPR-Z])[1-9][A-HJ-NPR-Z]$

from regexp-examples.

anderstroker avatar anderstroker commented on May 31, 2024

Thank you so much, my friend... I will try

from regexp-examples.

Related Issues (17)

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.