roymustang86
roymustang86

Reputation: 8563

regex to match either single, double or triple digit

I am trying to find all instances of places where (x,y) have been used in my code where x and y are integers.

I tried [0-9]+,[0-9]+

This could detect (0,2) (3,5) etc, but it doesnt detect

(0,50) or (255,255)

How do I make the check inclusive for all numbers?

This not a programming language, this for Notepad++ and I think I had to include white spaces \s* before and after the commas

Upvotes: 2

Views: 7807

Answers (2)

doublesharp
doublesharp

Reputation: 27609

Use \d to match any digit, and curly braces to match 1-3 characters - \d{1,3}. For your full match use:

\d{1,3},\d{1,3}

If you want to include the parenthesis, they will need to be escaped:

\(\d{1,3},\d{1,3}\)

Upvotes: 4

Joseph Silber
Joseph Silber

Reputation: 219938

Try this regex:

\(\d{1,3},\d{1,3}\)

See it here in action: http://regexr.com?32jph


Here's the breakdown:

\( - matches a literal (
\d{1,3} - matches one to three digits
, - well, matches a literal ,
\d{1,3} - again, matches one to three digits
\) - matches a literal )

Upvotes: 8

Related Questions