JavaScript Learning Notes collation (Regular)

Source: Internet
Author: User

The RegExp object represents a regular expression, which is a powerful tool for performing pattern matching on strings
var re=/e/; var re=New RegExp (' e ');
Method of the String object of the regular expression

1.search---Retrieves the value that matches the regular expression (returns the subscript)

var a= ' a1a34b4cd5ef5g '; alert (A.search (' a '));          Results: 0alert (a.search (/\d{2}b/g));    Results: 3

2.match---found a match for one or more regular expressions (returns an array)

var a= ' a1a34b4cd5ef5g '; alert (A.search (' a '));         Results: Aalert (A.search (/a/g));        Results: A,a

3.replace (A, b)---Replace substrings that match regular expressions (returns new replaced strings)

A: Required. A RegExp object that specifies a substring or pattern to replace

B: Required. A string value. A function that prescribes replacement text or generates alternate text

var a= ' a1a34b4cd5ef5g '; alert (A.replace (' A ', ' B '));     Results: B1a34b4cd5ef5galert (A.replace (/a/g, ' B '));    Results: b1b34b4cd5ef5g

4.split (A, b)---Split a string into a string array (returns the segmented array)

A: Required. A string or regular expression that is split from the location specified by the parameter

B: Optional. This parameter specifies the maximum length of the returned array. If this parameter is set, the returned substring will not be more than the array specified by this parameter. If this argument is not set, the entire string will be split, regardless of its length

Test---Detects if a string matches a pattern, matches returns true, otherwise returns false

JavaScript Learning Notes collation (Regular)

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.