Web knowledge: Using regular expressions in JavaScript

Source: Internet
Author: User
Tags expression regular expression string
Javascript| Web Page |

In JavaScript, there are two ways to use regular methods, one is to create an instance of a regular expression, but rather to use a regular expression in a string object to relate the method.

First, there are 2 ways to create regular expressions:

var my_regex=/[a-z]+/g;
var my_regex=new ("[a-z]+", "G");

Method

EXEC (string), which is regular processing of a string and returns the result of the match.
Test (string), which tests whether a string contains a matching result

Regular in a String object

Method

Match (pattern) is a regular match based on pattern and, if matched to, returns a matching result, such as a match that does not return null
Search (pattern) is a regular match according to pattern, if the match to a result, then return its index number; otherwise return-1
Replace (pattern,replacement) is a regular match based on pattern, and the matching result is replaced by replacement
Split (pattern) is a regular segment based on pattern, which returns a segmented array.



Related Article

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.