simpleregex / srl-php Goto Github PK
View Code? Open in Web Editor NEWSimple Regex Language
Home Page: https://simple-regex.com
License: MIT License
Simple Regex Language
Home Page: https://simple-regex.com
License: MIT License
The word number implies a sequence of one or more digits (perhaps with an optional hyphen at the start) while it actually represents a single digit in SRL (see the port capture group in the URL valdiation section here), so "number" should be renamed to "digit" as this is exactly what it represents. Perhaps "number" could then be implemented as an acutal sequence of multiple digits.
I'm giving a talk on regular expressions at the PyOhio Conference this year. A lot of the talk will be in a Juypter Notebook using the Python implementation of SRL. I'm going over the documentation on the web site and only see provisions begin/end (of string) anchors. Is there none for begin/end of words, Words?
Tom Fetherston
I am wrong or i can't do this regex : ((data-id)="|src=")
I tried lots of thing, my last attempt is this one :
capture ( any of ( ( capture(literally 'data-id'), literally '="' ), (literally 'src="') ) )
The SRL Query contains an error: Non-matching parenthesis found.
Any chance to change the license to something that we could use in proprietary software?
Something like this: http://www.phpliveregex.com/ but for SRL would be very useful to test on the fly.
Also a suggested feature would be to generate links that include the SRL base64 encoded in the URL so they can be thrown in comments in the code if we just used the generated regex, to refer back to the SRL and edit it.
This idea came to me when I read this bit in the README
But if you like, you can build the expression somewhere else and just use the result in your app. If you do that, please keep the code for that query somewhere and link to it, otherwise the Regular Expression will be unreadable just as before.
This would be a killer feature for this project - being able to take existing regex and output a pretty printed SRL expression for it. That would allow verification and and modification of existing regexes much, much easier.
I'm .NET developer, I found this amazing repo and I would like to see a C# implementation of SRL.. Do you know if there is someone working on this? What do I need to help?
Hi, I have been trying to build a query that matches the following string but without much success:
( foo bar -- quux)
(()()()()()))))
(hello world"\)
Whitespaces are trimmed when using "literally":
Is there a way to use back references?
The query
begin with (digit once),
any of (letter, digit, uppercase letter) once or more,
must end
fails to compile, with the error
The SRL Query contains an error: Invalid parameter given for
digit
.
But the same query, if rewritten as
begin with (digit once),
any of (uppercase letter, letter, digit) once or more,
must end
...seems to compile correctly, and matches my test string 1ABCdef
. From the error message, I guess uppercase is being passed as a parameter to digit
in the first example?
Do they accept both SR expressions and strings? Do parentheses after them required?
I'm trying to write the parser, but can't precisely figure out the syntax of lookarounds.
Hi Karim,
I think you should translation files on your project. I want your query translate to turkish.
As a Java developer, I would love to see a Java implementation of SRL.
Hi all,
I get interested in SRL and I am trying to build a C++ library for "compiling" SRL into regex string, and the library is about to be finished.
And I think no one else has plan to do so (yet?). So if you think it's a good idea, maybe you could create a repo SimpleRegex/SRL-CPP and grant me the privilege to edit it so that I could directly work on it.
Thank you!
Hi there,
Since PHP 8.0 "Match" is a reserved PHP keyword, which throws a 500 when loading the class "Match" from SRL.
This breaks the package on any PHP 8.0+ versions
the first exemple of this lib is a very basic email matching regexp. I would suggest to replace this with something else. Using regexp for matching email addresses is often a bad idea and this example suggests it's fine and/or that this regexp is actually correct for validating email
https://fightingforalostcause.net/content/misc/2006/compare-email-regex.php
It would be great to have inverse behavior.
User provides:
/^([A-Z0-9._%+-])+@[A-Z0-9.-]+\.[A-Z]{2,}$/i
Output:
begin with any of (digit, letter, one of "._%+-") once or more,
literally "@",
any of (digit, letter, one of ".-") once or more,
literally ".",
letter at least 2,
must end, case insensitive
I'm working on a python implementation of srl and I'm wondering why literally
creates a noncapturing group i.e. (?: ...)
I think is a very interesting project, has any updated?
From this page: https://simple-regex.com/welcome. PHP and Composer sample code:
$srl = new SRL('literally "color: ", capture (letter once or more) as "color", literally "."');
$matches = $regEx->getMatches('Favorite color: green. Another color: yellow.');
echo $matches[0]->get('color'); // green
echo $matches[1]->get('color'); // yellow
SRL instance variable is defined as $srl
but is used as $regEx
.
Looks much like verbal regex (verex)
In English, "either" means a choice between two ("Choose either A or B). For three or more, the word is "any" (Choose any of these: A, B, C, or D). The "either" keyword is jarring and confusing.
How about changing "Either" to "Any", because that seems to be the syntax--"any of the following".
Is there a way to represent negated character classes? e.g. [a-z]{2}[^0-9]
? Neither of these seem to work:
letter exactly 2 times,
not digit
letter exactly 2 times,
no digit
...incidentally, both of these generate the regular expression [a-z]{2}[0-9]
โ I'm not sure if this is a bug, or just an expected consequence of an unrecognized keyword.
SRL Query:
capture (anything) as "basename"
Expected Regular Expression:
/(?<basename>.)/
Actual Regular Expression:
/(?<basename>.)(?:(?:basename))/
Every other name besides "basename" generates the desired result. When supplying "basename" (case insensitive) as capture name, an additional literally-check will be added.
I'm currently building something quite complex with Regular Exp in JS and would love to have this implemented in JS.
Hi,
I like your language for regex, nice work.
But still, looking #at code of regex you can not say what it for.
I have another idea and approach for regex: splitting.
username@domain.com
where
username = [A-Z0-9._%+-]+
domain = ([0-9]|[a-z]|[\.-])+
com = [a-z]{2,}
insensitive
Another example:
protocol://domain:port/path?parameters
where
protocol = [a-z]+
domain = [a-z]+(?:[a-z]|(?:\.))+[a-z]{2,}
port = [0-9]+
path = ((?:\/).*?)part(?:\?)? where
part = (?:(?:\?)|$)
parameters = .*?
insensitive
What do you think?
Hi
I like the project but have not had the possibility to use it yet in my work projects but I am coming up to one project that will have heavy use of it. I like regular expressions and to use them but I usually need to consider other developers
I am thinking of rewriting it in ANTLR 4 to have the generation being done from common rules and use the tests on the languages in the ANTLR languages to make it easier to maintain. I see that as needed as I can see that it is long time since maintenance have been done on the repositories in any form or way.
For C# support I afterwards want to make a T4 template where I can increase the developer experience even further
How to implement something like {2,5}
in SRL? If it is not possible at all, please add it.
I'd like to help with this but I think I'm to new to regex to be able to do it all myself.
hi there, I would like to ask someone experienced in gem/shard writing to write a gem/shard for SRL, thanks
Already suggested from Reddit:
exactly
as synonym to literally
either
as synonym to either of
It makes it easier and better to write tests among the different languages and ensures consistency. We could use a simple syntax similar to SimpleTest. This allows the language to separately interpret the test files, use the language's code to run the test and ensure the correct stuff is matched (and correct regex is generated). The current .rule
syntax may be good enough for this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.