Remove comma from group regex

Is it possible:

U.S. Patent 6,570,557

extract 3 groups:

  • USA
  • patent
  • 6570557 (no commas)

So far I have received:

(US)(\s{1}Patent\s{1})(\d{1},\d{3},\d{3})

and tried to (?!,)get rid of the commas, then I really get rid of the whole number.

+5
source share
4 answers

Try:

var input   = 'US Patent 6,570,557',
    matches = input.match(/^(\w+) (\w+) ([\d,]+)/),

    code = matches[1],
    name = matches[2],
    numb = matches[3].replace(/,/g,'');
+9
source

Instead of using a regular expression, you can do this with two simple functions:

var str = "US Patent 6,570,557"; // Your input
var array = str.split(" "); // Separating each word
array[2] = array[2].replace(",", ""); // Removing commas
return array; // The output

It should also be faster.

+2
source
0

:

(US)(\s{1}Patent\s{1})(\d{1}),(\d{3}),(\d{3})

3

0

All Articles