Js RegExp Object

Source: Internet
Author: User

1 syntax

1.1 Direct Volume syntax

/pattern/attributes

1.2 Creating a RegExp Object

New RegExp (pattern, attributes)

1.3 Description

Pattern is a regular expression, attributes refers to modifiers such as I,g,m

2 RegExp Object Methods

Method Description
Exec Retrieves the value specified in the string. Returns the found value and determines its location.
Test Retrieves the value specified in the string. Returns TRUE or FALSE.
        Syntax: Regexpobject.test (String)        //Description: The test () method retrieves the specified value in the string. The return value is True or False        var Re1 = new RegExp ("^\s+$", "G");        var msg = re1.test ("he llo"); alert (msg);        Syntax: Regexpobject.exec (String)        //Description: The EXEC () method retrieves the specified value in the string. The return value is the value that was found. If no match is found, then null        var A is returned;        var Re2 = new RegExp ("E", "G");        do {            a = re2.exec ("Hello World hi!");            alert (a);        }        while (a! = null)

3 Methods for String objects that support regular expressions

Method Description
Search Retrieves a value that matches a regular expression.
Match Finds a match for one or more regular expressions.
Replace Replace the substring that matches the regular expression.
Split Splits a string into an array of strings.
        Syntax: Stringobject.search (regexp)        //Description: Search () is retrieved from the beginning of the string and always returns the first matching position of Stringobject        var re3 = new RegExp (" World ");        var a = "Hello World". Search (Re3);        alert (a);        Syntax: Stringobject.match (searchvalue)        //Description: The match () method can retrieve the specified value within a string, or find the match for one or more regular expressions        var s = "Hi baby! hi! ";        var a = S.match (/hi/);        Alert (a instanceof Array);

Js RegExp Object

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.