I've been trying to write a regex to stictly match the following patterns -
3+
, 3 months +
, 3+ months
, 3m+
, 3 years +
, 3y+
, 3+ years
.
I've written a pattern - [0-9]{1,2}\s?(m|months?|y|years?)?\s?\+
which works for most of the cases exept the 3+ months
& 3+ years
here it matches just the 3+
part and not the month part. I want to use the matched string somewhere and this causes an issue. To accomodate this I tried adding another group to make the regex look like [0-9]{1,2}\s?(m|months?|y|years?)?\s?\+ (m|months?|y|years?)\s|$
but this is also matching for 6+ math
. Can someone help me with what the issue is here, also can this regex be improved?
I can use multiple regex to solve different different use cases, but I wanted to achieve this using only 1 regex.
Thanks
6+ math
shouldn't match at all or should match6+
out out it? Are all inputs on separate lines?