Reputation: 35
I am trying to capture the last numbers from "hpercent=" in the string but only if it falls into a range from 1-25.
sample strings:
desired output from "hpercent": 10, 25, 2
I tried:
Get the last digits: [^=]+(?=$)
My range for only numbers 1-25: ^[1-9]$|^1[0-9]$|^2[0-5]$
just not sure how to put the above regex together in one expression
UPDATE:
Sorry, very new to this. but I guess I need to capture the last number as a group. but as you can see when it captures the last number it IS beyond 25.
I should only capture between 1-25.
Upvotes: 0
Views: 232
Reputation: 16958
Just to put your regexes together in one expression:
/([1-9]|1[0-9]|2[0-5])(?=$)/
Upvotes: 0
Reputation: 936
Since you didn't specify what's your regex flavor nor programming language you're using, here's a solution using vim:
/\v\=(\d|1\d|2[0-5])$/
What's going on:
=
and EOL
($
)It should be easy to convert this to your regex flavor.
Upvotes: 0
Reputation:
This should work hpercent=([1-9]|1[0-9]|2[0-5])(?![0-9])
Expanded
hpercent=
( [1-9] | 1 [0-9] | 2 [0-5] ) # (1)
(?! [0-9] )
Simplified by a number range regex generator tool
Upvotes: 1