Since the rule name can be any alphanumeric string including _ a simple "\w+" won't suffice.
I should think something like [\w\_]+ would work:
#!/usr/bin/perl use strict; use warnings; my $testval = "KUNG_FOO=bar"; if ($testval =~ /([\w\_]+)/) { my $keyname = $1; print "KEY = [$keyname]\n"; } exit; __END__ C:\Steve\Dev\PerlMonks\P-2013-10-16@0800-Underscore>testregex.pl KEY = [KUNG_FOO]
In reply to Re: Lexing: how to define tokens based on "context"
by marinersk
in thread Lexing: how to define tokens based on "context"
by three18ti
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |