#!/usr/bin/perl -w
use strict;
use re 'debug';
my $test = "abc123abc1234abc";
$test =~ /(\d{4})/;
print $1;
The output from that is:
Compiling REx `(\d{4})'
size 8 first at 5
1: OPEN1(3)
3: CURLY {4,4}(6)
5: DIGIT(0)
6: CLOSE1(8)
8: END(0)
stclass `DIGIT' minlen 4
Matching REx `(\d{4})' against `abc123abc1234abc'
Setting an EVAL scope, savestack=5
3 <abc> <123abc123> | 1: OPEN1
3 <abc> <123abc123> | 3: CURLY {4,4}
DIGIT can match 3 times out of 4...
Setting an EVAL scope, savestack=5
failed...
Setting an EVAL scope, savestack=5
4 <abc1> <23abc123> | 1: OPEN1
4 <abc1> <23abc123> | 3: CURLY {4,4}
DIGIT can match 2 times out of 4...
Setting an EVAL scope, savestack=5
failed...
Setting an EVAL scope, savestack=5
5 <abc12> <3abc123> | 1: OPEN1
5 <abc12> <3abc123> | 3: CURLY {4,4}
DIGIT can match 1 times out of 4...
Setting an EVAL scope, savestack=5
failed...
Setting an EVAL scope, savestack=5
9 <23abc> <1234abc> | 1: OPEN1
9 <23abc> <1234abc> | 3: CURLY {4,4}
DIGIT can match 4 times out of 4...
Setting an EVAL scope, savestack=5
13 <23abc1234> <abc> | 6: CLOSE1
13 <23abc1234> <abc> | 8: END
Match successful!
1234Freeing REx: `(\d{4})'
It's fairly complicated, but if you really need to get into the guts of how regular expressions work, that should do it.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats. |