The regular expression search () function

Source: Internet
Author: User

The regular expression search () function:
This function can retrieve substrings that match a regular expression.
The return value is the starting position of the first substring that matches the regular expression, and the position is calculated starting at 0. Returns-1 if not found.
This is only a section of the search () method for a string object that directly retrieves sub-characters, which are related to the regular expression.
Syntax structure:

Stringobject.search (RegExp)

The parameter list is as follows:

RegExp required. The regular Expression object.

Browser support:
This method is supported by IE browser.
This method is supported by the Firefox browser.
Google Chrome supports this method.
Instance code:
Example one:

var str= "I love Antzone"; var reg=/ant/ Console.log (Str.search (reg));

The above code can return the starting position of the substring "Antzone" in the string where the regular expression matches.
Example two:

var str= "I love Antzone"; var reg=/abc/ Console.log (Str.search (reg));

There are no strings in the string that the regular expression will match, and this function returns-1.

The original address is: Regular expression search () function

The regular expression search () function

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.