user2329342
user2329342

Reputation: 43

Regular expression for matching numbers without commas

I am stuck trying to get numbers without commas in front of a number.

Here is what I am using:

^(\d{1,3})$|(,\d{3})$

Here is the match:

3
62
115
112,266,455
989,564,654
137,150
,137,150

I don't want ,137,150.

Upvotes: 3

Views: 114

Answers (1)

Ry-
Ry-

Reputation: 225281

Assuming those matches you listed should all be the same match, you should combine those groups and allow ,### to be repeated any number of times:

^\d{1,3}(,\d{3})*$

Upvotes: 2

Related Questions