SRL - Simple Regex Language

Regular Expressions Made Simple
Get Started View On GitHub

A Short Example

No one wants to read. So let's have a look at a short example before we start. First, you'll see a boring Regular Expression as you may know them. Can you already guess what we're trying to validate?

Regular Syntax:

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

No? Well... Let's try the Simple Regex Language then. In the box below, you can see the exact same expression, but with a much cleaner syntax. Yes, it's quite long compared to the one on the top, but let's be honest.. It's not always about the size, right?

SRL Syntax:

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 times,
must end, case insensitive

Test Input

Run Query!

SRL Query is matching!

SRL Query is not matching.

The SRL Query contains an error:

Whoops... you may have found a bug.

Generated Regular Expression:


        

Looks like we're trying to validate an email address. In reality, you might not want to use a Regular Expression for that, since emails are pretty painful to validate and there are plenty of tools out there that do a way better job on that, but for our example, it fits just fine. Especially for the one below.

Oh, and did we mention you can edit and explore all the SRL Queries shown on this page? Just click on the desired query and be surprised.

All SRL Queries directly translate into basic Regular Expressions. That way you're able to create your SRL Queries on this page and use the resulting Regular Expression in any language afterwards. But more on that later...

Let's Match Something

Okay, okay, you're validating strings in a fancy way. That's nice and all, but what about filtering? I want to get some matches!

Not a problem. In this example, we'll take the SRL from above and add a few capture groups. This way we're able to filter the local part and the domain of an email address from a text.

SRL Syntax:

capture (any of (digit, letter, one of "._%+-") once or more) as "local",
literally "@",
capture (
    any of (digit, letter, one of ".-") once or more,
    literally ".",
    letter at least 2 times
) as "domain", case insensitive

Test Input

Run Query!

SRL Query is matching!

SRL Query is not matching.

The SRL Query contains an error:

Whoops... you may have found a bug.

Generated Regular Expression:


        

Go ahead! Press "Run Query!" and see what happens. You'll see two matches, each containing two match groups: local and domain. We defined those names in the SRL above, after the CAPTURE group in the AS directive.

Using SRL: Website, PHP 7, JavaScript or Python?

There are a few ways of using SRL. You can either build your desired SRL Query on this website and afterwards use the generated Regular Expression in your language and code of choice, or, if you're already using PHP 7, JavaScript or Python, you can require SRL in your project and then use all of its features right out of the box.

For more information on that, please see the GitHub projects and choose your language. There you'll find some nice features like the SRL Query Builder which will allow you to easily generate dynamic Regular Expressions and much more.

And of course if you like, feel free to help us implementing this project in other programming languages. Just have a look at the Contribution section.

What About lookbehind? And Lookahead? And Replace? And...

Relax. It's all there. If you like the concept and want to dig deeper, you're welcome to browse the documentation, try out a few more examples or just get started right away!

Of course, since this project is completely open source, feel free to check out the complete sources on GitHub. And if you like, go ahead and make a contribution. We're only beginning our journey and have many things left to do. You could write some tests, report or squash some bugs, extend SRLs feature set, improve existing features, extend its documentation or even implement it in another language. We'd love to see more languages with SRL support!

And if you feel like this project is worth being shared, a short post about it on your favorite social media platform would be absolutely fantastic.