0

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?

Bohemian
  • 412,405
  • 93
  • 575
  • 722
chrispepper1989
  • 2,100
  • 2
  • 23
  • 48

3 Answers3

6

You can use this regex to match any digit >= 10:

^"MyId":[1-9][0-9]+$

RegEx Demo

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.

anubhava
  • 761,203
  • 64
  • 569
  • 643
0

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.

Andy G
  • 19,232
  • 5
  • 47
  • 69
0

If you need exact match to any number greater than 9 ^"MyId":[1-9][0-9]+$

reconnect
  • 306
  • 3
  • 13