SimpleRegex/SRL-PHP

Another approach in regex.

antonmedv opened this issue · 2 comments

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?

Thanks for the positive words. I like your syntax, too, and I think it's way cooler than plain regex, but it's still too complicated for beginners. I was aiming to simplify regex to make it understandable by everyone. I know it's verbose and that may suck, but it can be understood pretty good.

SRL should never replace the regex syntax entirely. It should just be easier for developers writing one regex per year. Your syntax on the other hand may have potential to replace them, since it's compact and (at least in my opinion) makes way more sense than regex. I just don't like that it requires new lines, since otherwise you'd need some separator, but that's just peanuts.

Where can be something like this:

regex('username@domain.com')
->where()
->set('username', '[A-Z0-9._%+-]+')
...

But i think newlines can be skiped:

regex('username@domain.com where username = [A-Z0-9._%+-]+ and domain = ([0-9]|[a-z]|[\.-])+ and ...');

Or:

regex(<<<REGEX
  username@domain.com
  where
    username = [A-Z0-9._%+-]+
    domain = ([0-9]|[a-z]|[\.-])+
    com = [a-z]{2,}
  insensitive
REGEX;);