Reputation: 2190
My regex is weak, in the case of the following string
"OtherId":47
"OtherId":7
"MyId":47 (Match this one)
"MyId":7
I want to pick up the string that has "MyId" and a number that is not 1 - 9
I thought I could just use:
RegEx: How can I match all numbers greater than 49?
Combined using: Regular Expressions: Is there an AND operator?
But its not happening... you can see my failed attempt here:
https://www.regextester.com/index.php?fam=99753
Which is
\b"MyId":\b(?=.*^[0-10]\d)
What am I doing wrong?
Upvotes: 0
Views: 1247
Reputation: 346
If you need exact match to any number greater than 9
^"MyId":[1-9][0-9]+$
Upvotes: 0
Reputation: 786329
You can use this regex to match any digit >= 10
:
^"MyId":[1-9][0-9]+$
If leading zeroes are to be allowed as well then use:
^"MyId":0*[1-9][0-9]+$
[1-9]
makes sure number starts with 1-9
and [0-9]+
match 1 or more any digits after first digit.
Upvotes: 6
Reputation: 19367
Essentially, you are looking for 2 or more digits:
\"MyId\"\:(\d{2,})
I have escaped the quotes and colon, and {2,}
means 2 or more.
Upvotes: 0