Regular expression Learning examples

Source: Internet
Author: User

Example one:

Regular: (? <= (Href|src|filepath) =) \s+? (\.jpg|\. JPG)

Parsing: The expression is divided into three segments

First paragraph:

(? <= (Href|src|filepath) =) Gets the starting position meaning that the match begins after the three characters that begin with href=, src=, and filepath=.

Use the regular (? <=pattern), if not < then start matching from that character.

Second paragraph:

\s+? The middle of the configuration character. Attention? Represents the minimum match, that is, the first one to match.

Third paragraph:

(\.jpg|\. JPG) The end of the character meaning is the position at the end of the. jpg or. jpg.

This expression can be used to obtain an HREF or src or an address behind a filepath.

For example,

Match result is http://avatar.csdn.net/8/3/2/1_xanxus46.jpg

Example Two

Regular: (.) \\1 (.) \\2

The expression to use

\num matches num, where num is a positive integer. A reference to the obtained match. For example, "(.) \1 "matches two consecutive identical characters. Parse: Match two (can be same) duplicate character, for example: HTTTPP match result TTPP (not same) HTTTTPP match result is tttt (same)


Regular expression Learning examples

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.