JS Regular Expression method: a regular in front, a regular in the back:
Use:
1.exec
var res =/\-[a-z]/g. exec ("Font-size");
Console.log (RES);
The results obtained:
So the return is an array, the first one is the matching value, the second is the matching position, the third is the number of inputs.
2.test
var res =/\-[a-z]/g. Test ("font-size");
Console.log (RES);
Returned as a Boolean value
3.match
var res = ("Font-size-style"). Match (/\-[a-z]/g);
Console.log (RES);
Returns the value that is matched to
4.replace
("Font-size-style"). Replace (/\-[a-z]/g, function (a,b,c) {
Console.log (a);
Console.log (b);
Console.log (c);
});
The returned a is the matching value, B is the index value, and C is the input value; when there are multiple values, such as a set of loops, this is ideal for matching multiple values
Replace is used to match the global, match the first letter
Reference link: https://www.w3cschool.cn/regexp/m2ez1pqk.html (w3cschool)
The match test exec replace function of the JS regular expression