How can I use regex to capture this specfic set of ages? -
i have set of age data, below;
1 2 3 4 5 6 7 8 9 10 1,1 1,2 1,3 2,12 11,13,15 7,8,12 12,15 14,16,17 15,6 13,11,10,2
and on... trying use regex in target 'mixed' range of childrens ages. logic requires @ least combination of 2 childen (so requires 1 of lines comma), @ least 1 aged under 10 (min 1), , @ least 1 aged equal or greater 10 (max 17).
my expected results above return these lines below, , nothing else;
2,12 7,8,12 15,6 13,11,10,2
any advice appreciated on how resolve? in advance, continuing try correct.
you can use regex meet requirements:
^(?=.*\b[1-9]\b)(?=.*\b1[0-7]\b)[0-9]+(?:,[0-9]+)+$
- there 2 lookaheads assert 2 numbers 1 between
1-9
, between10-17
([1-9])
matches number should between1
,9
1[0-7]
matches number should between10
,17
[0-9]+(?:,[0-9]+)+
in regex matching 1 or more comma separated numbers in middle.
Comments
Post a Comment