JavaScript: Find/Match

Source: Internet
Author: User

one, provided in the stringCharAt () returns the character at the specified position.
Example: ' abc '. CHARAT (1); "B"
charCodeAt () returns the Unicode encoding of the character at the specified position.
Example: ' abc '. charCodeAt (1); 98

IndexOf (Searchvalue,fromindex) retrieves the string and returns the corresponding subscript.
Example: ' Abcabc '. IndexOf (' B ', 0); 1
' Abcabc '. IndexOf (' B ', 2); 4
Search (REGEXP) retrieves the value that matches the regular expression and returns the corresponding subscript.
Example: ' Abcabc '. Search (' B '); 1
' Abcabc '. Search (/B/IMG); 1
Match(regexp) found a match for one or more regular expressions, did not return NULL, otherwise returns an array
Example: ' Abcabc '. Match (' B '); ["B"]
' Abcabc '. Match (/B/IMG); ["B", "B"]
PS: The above regexp, can be substrings, can also be regular.
Second, RegExpDirect Volume Syntax:/pattern/attributes
Syntax for creating REGEXP objects: New REGEXP (pattern, attributes);
The regexpobject.lastindex is used to specify the starting position of the next match.
Attributes
I perform a match on case insensitive.
G performs a global match (finds all matches rather than stops after the first match is found).
M performs multi-line matching.

(1) regexpobject.exec (string) returns an array that holds the matching results, and returns NULL if it is not retrieved.
Example 1:
/c/img.exec (' ABCDEFGC ');  [' C ']new RegExp ("C", "IMG"). EXEC (' ABCDEDGC '); [' C ']/c/img.exec (' a ');  Null
Example 2:
var reg = new RegExp ("C", "Im"); Reg.exec ("Abcabc");    ["C"]reg.lastindex;    0var reg = new RegExp ("C", "IMG"); Reg.exec ("Abcabc");    ["C"]reg.lastindex;    0TYPEOF reg;    "Object" Object.prototype.toString.call (reg);    "[Object RegExp]"
(2) test retrieves the value specified in the string. Returns TRUE or FALSE.
Example:
/c/img.test (' ABCDEFGC ');  Truenew RegExp ("C", "IMG"). Test (' ABCDEDGC '); True

JavaScript: Find/Match

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.