in reply to Lexing: how to define tokens based on "context"
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]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Lexing: how to define tokens based on "context"
by dave_the_m (Monsignor) on Oct 16, 2013 at 14:38 UTC | |
by marinersk (Priest) on Oct 16, 2013 at 16:56 UTC |