Skip to content
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

Regexp literal capture #69

Merged
merged 4 commits into from
Jul 28, 2020
Merged

Regexp literal capture #69

merged 4 commits into from
Jul 28, 2020

Conversation

skx
Copy link
Owner

@skx skx commented Jul 28, 2020

This pull request closes #68 by allowing captures inside regular expression literals:

ip = "192.168.1.1";

if ( ip ~= /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/  ) {
   printf("Matched! %s.%s.%s.%s\n", $1, $2, $3, $4 );
}

skx added 4 commits July 28, 2020 13:47
Much like Perl the capture-group contents are accessible via
$1, $2, .. $N
We constrain them to be valid only for the duration of an `if`
statement.  This uses the same approach we used for our `foreach`
handling.
@skx skx merged commit 9fab472 into master Jul 28, 2020
@skx skx deleted the regexp-literal-capture branch July 28, 2020 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Literal regular expressions should allow captures
1 participant