in reply to Regex Question
G'day shealyw2,
index is another option:
Update: Oops! Left off the POSITION (index STR,SUBSTR,POSITION). Thanks, Ratazong. Here's an improved version.
$ perl -Mstrict -Mwarnings -E ' my $x = "abc"; say $x if index($x, "a", 2) == 2; my $y = "cba"; say $y if index($y, "a", 2) == 2; my $z = "aba"; say $z if index($z, "a", 2) == 2; ' cba aba
$ perl -Mstrict -Mwarnings -E ' my $x = "abc"; say $x if index($x, "a") == 2; my $y = "cba"; say $y if index($y, "a") == 2; ' cba
Note: index is based at zero (1st char = 0; 3rd char = 2)
-- Ken
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Regex Question
by Ratazong (Monsignor) on Nov 26, 2012 at 08:30 UTC | |
by kcott (Archbishop) on Nov 26, 2012 at 08:43 UTC |
In Section
Seekers of Perl Wisdom