Hacker News new | comments | show | ask | jobs | submit login

I think what most people mean when they say 'regex' is actually 2 thing:

1. The syntax of that pcre-like regex engine accept.

2. regular language, a kind of formal language.

Many regex engine nowadays like the one in perl5 and onigmura already breaks 2, but still makes 1 compatible. I think what perl6 does is also breaks 1. (I am not experienced in Perl6. Please correct me if I am wrong.) I don't think it is a problem, though.




In Perl 6 regexes are a type of method, and you can use them in grammars which are a type of class. (You can use them on their own as well)

Which means you can subclass grammars, compose in regexes with roles, and have parameterized regexes.

The syntax has also had an overhaul to make it more consistent with itself as well as the rest of Perl 6. Since you can embed Perl 6 code, some features of other regular expression engines haven't been implemented as they aren't needed.

The result of using a regex or grammar is also now a parse tree rather than True/False or the matched substring.

I generally recommend reading the code for JSON::Tiny::Grammar as a quick example of what it is like. https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra...


> I think what perl6 does is also breaks 1.

No, you can use the backward-compatible syntax if you don't want to spend any time porting to the newer improved syntax.

https://docs.perl6.org/language/regexes#Perl_5_compatibility...

http://design.perl6.org/Differences.html#New_regex_syntax

https://docs.perl6.org/language/5to6-nutshell#Add_:P5_or_:Pe...




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: