RegExp objects in JavaScript

Source: Internet
Author: User

The RegExp object in JavaScript is an intrinsic global object that holds information about the pattern-matching of regular expressions. How to use:

Regexp.property

The mandatory option property parameter is any of the properties of the RegExp object. REGEXP objects cannot be created directly, but can always be used. Before a successful regular expression lookup is complete, the initial values for each property of the RegExp object are as follows:

Attribute shorthand initial value

Index-1www.hljmlyfcyy.com

LastIndex-1

lastmatch$& an empty string.

lastparen$+ an empty string.

Leftcontext an empty string.

Rightcontext an empty string.

$-$9$1-$9 empty string.

Before a successful regular expression lookup is complete, its property value is undefined.

Do not confuse a global RegExp object with a regular expression object. Although it sounds like one thing, they are very different. The properties of the global RegExp object contain constantly updated information about each occurrence, whereas the regular expression object contains only the information that appears to match the regular expression.

The following example illustrates the use of RegExp objects in global JavaScript.

function Matchdemo () {

var s;

var re = new RegExp ("D (b +) (d)", "IG");

var str = "CDBBDBSBDBDZ";

var arr = re.exec (str);

s = "$ contains:" + regexp.$1 + "\ n";

S + = "$ contains:" + regexp.$2 + "\ n";

S + = "$ contains:" + regexp.$3;

return (s);

}www.hrbfc120.com

RegExp objects in JavaScript

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.