JS is intercepting a string between two strings

Source: Internet
Author: User
Match method
var str = "IID0000FFR"; var substr = Str.match (/id (\s*) ff/); Console.log (SUBSTR)

The returned result is: ["id0000ff", "0000"]

The \s* expression in () matches all strings

In high-level languages, we use a concept called quantitative words:

(? =ff) This represents the preceding string with the FF ending, but does not include the FF

var str = "IID0000FFR"; var substr = Str.match (/(\s*) (? =ff)/); Console.log (SUBSTR)

return array: ["iid0000", "iid0000"]

  

(iid=?) This represents a string that begins with the IID, but does not include the IID

var str = "IID0000FFR"; var substr = Str.match (/(iid=?) (\s*)/); Console.log (SUBSTR);

return array: ["IID0000FFR", "IID", "0000FFR"]

Get back and forth the middle string as the first example

var str = "IID0000FFR"; var substr = Str.match (/(iid=?) (\s*) (? =FFR)/); Console.log (SUBSTR);

return array: ["iid0000", "iid", "0000"]

JS is intercepting a string between two strings

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.