Js extracted string value

1 Like " Born in 1999 " string this string only contains an integer value directly using regular expressions to digital characters deleted the line: 

var str1 = ' born in 1999 ' ; var num1 = str1 .replace (/ [^ \ D] / G, '  ' );
 2 to match the string contained in a multi-value method, the use of string, all numbers by a regular expression character string is extracted (including integer and fractional): 

var STR = ' rice: 2.57 kg / yuan, cabbage: 3.65 yuan / kg ' ; var ARR = str.match (/ \ D + (\ + D) / G.?);     // ARR: [ "2.75", "3.65 "]

 

Guess you like

Origin www.cnblogs.com/zhizou/p/11368334.html