I will be very thankful if you can also explain to me the other metacharacters like + , * , (.) and backreferences
perlretut is a good start. For your question:
| coa | coma | comma | commma | commmma | |
| /com?a/ | ✔ | ✔ | ✘ | ✘ | ✘ |
| /com*a/ | ✔ | ✔ | ✔ | ✔ | ✔ |
| /com+a/ | ✘ | ✔ | ✔ | ✔ | ✔ |
| /co(mm)?a/ | ✔ | ✘ | ✔ | ✘ | ✘ |
| /co(m|mmm)a/ | ✘ | ✔ | ✘ | ✔ | ✘ |
| /com{2}a/ | ✘ | ✘ | ✔ | ✘ | ✘ |
| /com{0,2}a/ | ✔ | ✔ | ✔ | ✘ | ✘ |
| /com{2,3}a/ | ✘ | ✘ | ✔ | ✔ | ✘ |
| /com{3,}a/ | ✘ | ✘ | ✘ | ✔ | ✔ |
use warnings; use strict; use HTML::Tiny; my @tests = map { 'co'.('m'x$_).'a' } 0..4; my @regexes = do { no warnings 'qw'; qw/ com?a com*a com+a co(mm)?a co(m|mmm)a com{2}a com{0,2}a com{2,3}a com{3,}a / }; my $h = HTML::Tiny->new; print $h->table( {border=>1,cellpadding=>3,cellspacing=>0}, [ \'tr', [ \'td', '', map { $h->code($_) } @tests ], map( { my $r=$_; [ \'td', $h->code("/$r/"), map( { /$r/ ? $h->tag('font', {color=>'green'}, '✔') : $h->tag('font', {color=>'red'}, '✘') } @tests ), ] } @regexes ), ] );
In reply to Re: Conceptual doubt in metacharacters : Beginner in perl
by haukex
in thread Conceptual doubt in metacharacters : Beginner in perl
by Perl_Programmer1992
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |