javascript - Regular expression pattern for a string like 12,345,678,900? -


as can see title, write regular expression pattern find string consists of various numbers , separated comma every 3 digits. length of string can vary.

i still pretty new regular expression thingy can me that? lot in advance.

p.s. suggest of resources, website, books, etc, learning regular expression?

this regex shall match that:

\d{1,3}(?:,\d{3})* 

if want exclude match substring of ill-formed pattern, might want do:

(?:\a|[^,\d])(\d{1,3}(?:,\d{3})*)(?:\z|[^,\d]) 

explanation of first regex

\d{1,3}        1 3 consecutive numerals ,\d{3}         comma followed 3 consecutive numerals (?:,\d{3})*    0 or more repetition of non-capturing group of comma followed 3 consecutive numerals 

explanation of second regex

(?:\a|[^,\d])         non-capturing group of either beginning of string, or other comma or numeral (\d{1,3}(?:,\d{3})*)  capturing group of 1 3 consecutive numerals followed 0 or more repetition of non-capturing group of comma followed 3 consecutive numerals (?:\z|[^,\d])         non-capturing group of either end of string, or other comma of numeral 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -