Perl regex to extract groups of digits from string of dot

First off, I'm working with Perl 5.14.1.

I've been pulling my hair out over the following issue (NOTE: I absolutely suck at anything to do with regular expressions). I'm looking for a regular expression to extract only the numbers from strings such as the following:

E4.1
E6
e16
e6.7.3
E42.9

Basically, there's always an e (upper or lower case) followed by at least one group of digits. If there are multiple groups of digits, they are separated by a dot. What I want to do is to extract all groups of numbers into an array. For instance:

E4.1 -> ( 4, 1 )
E65 -> ( 65 )
e5.8.3 -> ( 5, 8, 3 )

where the stuff in parentheses is supposed to be the arrays of numbers I extracted from the strings.

What I got so far is

my @groupsOfNumbers = ( $inputString =~ /(d+)((.)d+)*/g );

My reasoning here was, there's always at least one group of numbers (hence the first (d+) ), optionally followed by any number of dot-followed-by-digits groupings (hence the ((.)d+)* part). Unfortunately this doesn't seem to work. For example, if I apply that regex to this input:

E4.3.1

the result is:

( "4", ".1", "." )

Please help!


你不必打扰点匹配,因为你只需要数字,

my @groupsOfNumbers = $inputString =~ /(d+)/g;
链接地址: http://www.djcxy.com/p/87016.html

上一篇: Java从url字符串中提取子字符串

下一篇: Perl正则表达式从字符串中提取数字组