Reputation: 73
I am stumped; I've tried a few things so far but what I am trying to extract is the first letter in a Perl string.
I have for example:
10emV
I want to use a regex to extract the first letter, which in this case would be e
.
Upvotes: 3
Views: 933
Reputation: 138027
You can simply search for \p{L}
, or [a-zA-z]
for ASCII letters. The first match is the first letter.
If you want to match the start of the string (for some reason), you can also use \A\P{L}*\p{L}
, or \A[^a-zA-z]*[a-zA-z]
.
See also: Perl regular expressions tutorial - More on characters, strings, and character classes
Upvotes: 6