New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable access to matched parts of a regular expression #229
Comments
This is also really easy to do on user side: see ConstExpr |
What about adding
|
As an example, I have a function As for the builtin you propose, I suppose it returns an array. I was hoping for something a little more magic as it would mean to write something like this:
And what happens if there is no match? I would prefer something like:
But I would understand that you don't like such magic variables as they make the language non-pure. |
I actually like this idea! Neat! I think it’s understandable what is going on here. |
Oh, great! It's how it is in Perl (I think, I don't remember exactly). |
Sorry to bump the old thread, here is a way to do this by extending expr.
Now the expression can be written like:
|
Expr supports variables inside expressions now. They also can be used:
|
TFS, @antonmedv . Where could I have learnt about this? Any non-obvious document or code-sample that I should keep an eye on, to know of such updates? |
I post all changes to https://github.com/expr-lang/expr/releases |
Hey!
It would be nice to be able to access the parts matching a regex when using the
matches
operator. The captured parts could be assigned to some variables ($1
,$2
, etc) or to a specialmatched
map indexed by the index and names of matched parts. All this could be done in a provided function, but putting it in the language allows one to get better performance as the regular expressions can be compiled at compile-time instead of at executing time.The text was updated successfully, but these errors were encountered: