JavaScript uses regular expressions to select value

var testString = "There are 3 cats but 4 dogs.";

var expression = /\d+/g;

var digitCount = testString.match(expression).length;

// one kind of special digital selector is the selector \dmeans is used to obtain a numeric string.

// In JavaScript, digital selector similar to:  /\d/g.

// add a plus sign after the selector ( +), for example: /\d+/git allows the regular expression matching one or more numbers.

// tail gis 'global' shorthand, which means allow this regex find all matches rather than just the first match.

Reproduced in: https: //www.cnblogs.com/chendi618/p/11000472.html

Guess you like

Origin blog.csdn.net/weixin_34248705/article/details/93234313