Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jnthn
Created February 13, 2013 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnthn/4945749 to your computer and use it in GitHub Desktop.
Save jnthn/4945749 to your computer and use it in GitHub Desktop.
use QRegexJVM;
sub try_match($s) {
# Create a cursor.
my $ci := NQPCursor.'!cursor_init'($s);
# Start it, match a digit.
my $c := $ci.'!cursor_start_cur'();
$c.'!cursor_pos'(0);
my $d := $c.digit();
# Get the Match object; boolify.
my $m := $d.MATCH();
$m.Bool()
}
say(try_match('5')); # 1
say(try_match('a')); # 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment