JavaScript Regular Expression (REGEXP)

Source: Internet
Author: User

What is RegExp

RegExp is a pattern used to describe what to retrieve.

Define RegExp

1 var New REGEXP ("mode");

Methods for RegExp objects

RegExp objects have 3 methods: Test (), exec (), compile ()

Test ()

Retrieves the value specified in the string. The return value is TRUE or False

1 var New REGEXP ("E"); 2 document.write (patt.test ("I am a Student"); 3 // return value 4 true

EXEC ()

Retrieves the value specified in the string. The return value is the found value, and null is returned if no match is found.

1 var New REGEXP ("E"); 2 document.write (patt.exec ("I am a student."); 3 //return value 4 E

A second parameter can be set to set the retrieval

G: Global Search

I: Perform a case insensitive match

M: Perform multi-line matching

1 var New REGEXP ("E", "G"); 2  Do {3     result = patt.exec ("I am a student in the university"); 4     document.write (result); 5  while NULL ); 6 // Execution Results 7 Eeenull

Compile ()

Used to change regexp.

That is, you can change the retrieval mode, or you can add or remove a second parameter.

1 var New REGEXP ("E"); 2 document.write (patt.test ("I am a Student"); 3 patt.compile ("B"); 4 document.write (patt.test ("I am a Student"); 5 // Output Results 6 TrueFalse

Summary from: http://www.w3school.com.cn/js/js_obj_regexp.asp

JavaScript Regular Expression (REGEXP)

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.