in reply to Please Help: A regular expression problem

Here's some code that lets you play with various patterns containing capture groups and also introduces the very useful @- and @+ arrays associated with the capture buffers. Try to explain the output from patterns like  (s(i(l+)y)) and in particular from  (is)|(si) versus  (si)|(is) regexes.

>perl -wMstrict -le "my $str = 'This is a silly sentence. {3}.'; REGEX: { print 'please enter your pattern: '; my $pattern = <STDIN>; chomp $pattern; last REGEX unless length $pattern; if ($str =~ m{$pattern}) { print qq{found match for '$pattern'}; print 'no captures' and redo REGEX unless $#- > 0; for my $n (1 .. $#-) { my $capture_n = substr $str, $-[$n], $+[$n] - $-[$n]; print qq{\$$n is '$capture_n'}; } } else { print qq{NO match found for '$pattern'}; } redo REGEX; } "