문제

I want to only match the digits from a comma seperated number. Example:

123,456 should match 123 and 456
75,432,444 should match 75 and 432 and 444

My expression currently looks like this \b[0-9]+(!\,)?+\b. It matches numbers that are NOT seperated with a comma, but it doesn't select numbers that are seperacted with a coma. If I seperate numbers with a | character or a space the numbers are selected.

Splitting the string is not an option. I'm trying to learn RegEx, but I'm now stumbled at this.

도움이 되었습니까?

해결책

You can try this regex:

\b(\d{1,3}(?:,\d{3})+)\b

It matches numbers that are separated by commas in group of three. Once you have the number in the capturing parentheses you can split on comma if you want to have its parts separated.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top