in reply to Parameterized Regex
What you demonstrated is called named captures, in Perl. In Python, it's called named groupings. I think that parameterized regexes are different.
sub match { my $args = shift; my $entity = $args->{entity}; my $quantity = $args->{quantity}; return $args->{target} =~ m/^(?:$entity){$quantity}/; } match ({entity => 'a', quantity => 5, target => 'aaaaa'}) && print "Ma +tch\n";
This is a little verbose, and wholly contrived, but the idea here is that you can pass into the regex things like metacharacters and quantifier totals, thus treating the regexp as a general template and letting the variables that get interpolated into it as specializations of the template. In this way, the regexp is accepting parameters, or is parameterized.
This use of parameterized seems consistent with other examples where this term, or the term parametric are used. Parametric templates in C++, for example, which allow for generic functionality to be specialized by binding parameters to a template.
I did some searching online on the name parameterized regex. The search results found a few hits that support my notion, and then one hit that presented a research paper on parameterized regexes. That paper was completely different from this explanation, diving into set theory and NFA and DFA state machines. So it's possible that casual use has rendered the term overloaded.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parameterized Regex
by Laurent_R (Canon) on Mar 03, 2017 at 07:34 UTC | |
by AnomalousMonk (Archbishop) on Mar 03, 2017 at 11:02 UTC | |
by Laurent_R (Canon) on Mar 03, 2017 at 23:33 UTC | |
|
Re^2: Parameterized Regex
by QM (Parson) on Mar 03, 2017 at 10:11 UTC |