Using regex in Perl, how do I find the first occurrence of any letter?

I'm at a standstill; I have tried several things so far, but what I'm trying to extract is the first letter in the Perl line.

I have for example:

10emV

I want to use a regular expression to extract the first letter, which in this case will be e.

+3
source share
3 answers

You can just search for \p{L}either [a-zA-z]ASCII letters. The first match is the first letter.

If you want to match the beginning of a line (for some reason), you can also use \A\P{L}*\p{L}or \A[^a-zA-z]*[a-zA-z].

See also: Perl Regular Expression Tutorial - more about characters, strings, and character classes

+6
if ( $string =~ m/([[:alpha:]])/ ) {
    print $1, $/;
}
0
my $let = $1 if '10emV' =~ m/([a-z]+?)/g;
print $let;
-1

All Articles