📜 ⬆️ ⬇️

SRL - Simple Regex Language

Classic dry rehex:

/^(?:[0-9]|[az]|[\._%\+-])+(?:@)(?:[0-9]|[az]|[\.-])+(?:\.)[az]{2,}$/i 

With a new taste of SLR:



The post does not pull the note, but the news completely. In order not to pull the cat by the tail, I brought the essence above habrakata. Now pull. In the spirit of Habra-Twitter, I beg to love and favor: simple-regex.com - the creation of regulars in simple language.
')
To begin with, it was not I who invented it, unfortunately. The site is in English, there is no article as such, so I cannot provide you with a translation. Today, I looked into the usual PHP poddit, and saw the topic “I’ve created a SQL-like language that compiles into regular expressions. " So, no more, no less. As written in one comment “Congratulations! You just made one of my most mystical skills obsolete! ”Therefore, I hasten to share with the Habra community so that everyone will be in the know.

Yes, this is a close to natural language way to create regulars. On the site you can find a few examples. The one that I brought up is checking email addresses.

And this one:

 begin with capture (letter once or more) as "protocol", literally "://", capture ( letter once or more, any of (letter, literally ".") once or more, letter at least 2 times ) as "domain", (literally ":", capture (digit once or more) as "port") optional, capture (literally "/", anything never or more) as "path" until (any of (literally "?", must end)), literally "?" optional, capture (anything never or more) as "parameters" optional, must end, case insensitive 

Serves to check the URL, and compiles into such a regularity that Habr does not even allow it to be displayed correctly, so I can’t insert it, sorry. But in the examples section there are many more examples. And they are colored on the site, it is more convenient to read there, so visit, you will not regret.



What I didn’t find on the site, but what is really being asked is the implementation of a chain of calls for setting conditions. But this is in the repository !

 $query = SRL::startsWith() ->anyOf(function (Builder $query) { $query->digit() ->letter() ->oneOf('._%+-'); })->onceOrMore() ->literally('@') ->anyOf(function (Builder $query) { $query->digit() ->letter() ->oneOf('.-'); })->onceOrMore() ->literally('.') ->letter()->atLeast(2) ->mustEnd()->caseInsensitive(); 

How useful this time will show. But for beginners to program it obviously makes it very easy to get familiar with regulars.

I honestly do not know who the author of this thing is, but it looks very interesting. Reddit topic posted by user AndroTux . Here is a link to the repository on GitHub . Here you can see that the only contributor to the project is Karim Geiger, who placed this project in the repository of tyvr.net , which is listed in his profile. Apparently, this is his own studio of programmers who program for money. I wish them good luck!

Source: https://habr.com/ru/post/308882/


All Articles