Reputation: 1
My script needs to find a specific linux kernel version using regular expressions - 3.13.0-24-generic.
I tried:
'((2\.[46])|(3\.[0-99])\.\d[^\/]*?) \(.*@.*\) [#]\d+.*'
but it doesn't work. How can I match my kernel version? Why does the regex above fail to match 3.13.0-24-generic?
Additional Info Based on Comments:
I am editing a SystemImager UseYourOwnKernel.pm script. The original script checks for either a 2.4 or 2.6 kernel:
my $regex =
# | kernel version + build machine
# `---------------------------------------
'(2\.[46]\.\d[^\/]*?) \(.*@.*\) [#]\d+.*' .
3.0,1,2, (i.e. single digit 3.X kernels) work with:
'((2\.[46])|(3\.[012])\.\d[^\/]*?) \(.*@.*\) [#]\d+.*'
I can get it to match the 3.13 and (3.0, 3.1, 3.2, etc) kernel using:
'((2\.[46])|(3\.[012]|3\.13)\.\d[^\/]*?) \(.*@.*\) [#]\d+.*' .
I need a numeric range that will match from 3.0 to 3.99 (this should take care of all 3.X releases).
Upvotes: 0
Views: 215
Reputation: 156
This code might help you:
(?:(?:[\d]|[1-9][\d])\.){2}(?:(?:[0-9]|[1-9][0-9])-){2}\w+
Upvotes: 0
Reputation: 174706
Your regex would be,
(?:[0-9]|[1-9][0-9])\.(?:[0-9]|[1-9][0-9])\.(?:[0-9]|[1-9][0-9])-(?:[0-9]|[1-9][0-9])-\w+
Explanation:
(?:[0-9]|[1-9][0-9])
Matches any number from 0-99.
\.
A literal dot.
-
A literal -
OR
A much shorter one,
(?:(?:[0-9]|[1-9][0-9])\.){2}(?:(?:[0-9]|[1-9][0-9])-){2}\w+
Upvotes: 2