Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove comma from group regex

Is it possible from this:

US Patent 6,570,557

retrieve 3 groups being:

  1. US
  2. Patent
  3. 6570557 (without the commas)

So far I got:

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

and was trying (?!,) to get rid of the commas then I effectively get rid of the whole number.

like image 786
ricardoespsanto Avatar asked Jan 22 '13 13:01

ricardoespsanto


1 Answers

Try with:

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

    code = matches[1],
    name = matches[2],
    numb = matches[3].replace(/,/g,'');
like image 116
hsz Avatar answered Oct 16 '22 23:10

hsz