Related methods of JS Regular Expressions (Regular Expression learning Note 1)

Source: Internet
Author: User

CopyCodeThe Code is as follows: var STR = "abcdefghijklnabcdefghijklmnabcabdefghijklmn ";
Re =/A/g;

Alert (Re. Test (STR ));
// If the test method is called, true or false is returned, indicating whether a matched character is found in the specified string. -- true

Alert(re.exe C (STR ));
// Returns the first string matching the expression in the string --

Alert (Str. Match (re ));
// Returns an array. Each item matches the expression array --- [a, a, a] note that g global variables must be used for regular expressions.

Alert (Str. Search (re ))
// Returns the position of the matched Regular Expression starting from 0 for the first time. The returned result is-1 -- 0 * a bit like indexof *

Alert (Str. Replace (Re, "B "))
// Replace. Needless to say *

Alert (Str. Split (re) [0])
// Split is generally used to divide a string into array objects and return the value of 0 in the array.

Regular Expressions can simplify many operations. Especially for form data verification.

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.