The match test exec replace function of the JS regular expression

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.