in reply to Regex partial/leading match
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my $bob = 'bob'; sub match { my ($string, $regex) = @_; say $string, "\t", $regex; my @chars = split //, $regex; for my $pos (1 .. $#chars) { my $re_part = join q(), @chars[0 .. $pos]; return 1 if eval { $string =~ /^($re_part)$/ and length $1 }; } return 0 } for my $regex ( 'bobly', 'bo*[a-z].', 'bob', 'bo(x)?bcd', 'fred', 'o*', ) { say match('bob', $regex); }
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex partial/leading match
by raymorris (Novice) on Dec 31, 2015 at 23:21 UTC |