Various regular expression instance usages

Source: Internet
Author: User
Select

Enclose all selections in parentheses, separating the adjacent selections by |. But with parentheses there is a side effect that the associated match is cached and available at this time?: Put the first option to eliminate this side effect.

Where?: one of the non-capturing elements, and two non-capturing elements are? = and?!, these two also have more meanings, the former is forward pre-check, in any beginning to match the position of the regular expression pattern within the parentheses to match the search string, the latter is a negative pre-check, Matches the search string at any start where the regular expression pattern does not match.

Back to reference

Adding parentheses around a regular expression pattern or part of a pattern causes the related match to be stored in a temporary buffer, and each captured sub-match is stored according to what is encountered in the regular expression pattern from left to right. The buffer number for the storage sub-match starts at 1 and continues numbering up to 99 sub-expressions. Each buffer can be accessed using ' \ n ', where n is a single or two-bit decimal number that identifies a particular buffer.

You can use the non-capturing metacharacters '?: ', '? = ', or '?! ' to ignore the save of the related match.


Operator precedence for various operators

The operations of the same priority are left-to-right, and the operations of different priorities are higher and lower than before. The precedence of the various operators is from high to low as follows:

Operator description

\ escape Character

(), (?:), (? =), [] parentheses and square brackets

*, +,?, {n}, {n,}, {n,m} qualifier

^, $, \anymetacharacter position and order

| "or" action


Some examples

Regular Expression Description

/\b ([a-z]+) \1\b/gi where a word appears consecutively

/(\w+): \/\/([^/:]+) (: \d*)? ([^#]*)/resolves a URL to a protocol, domain, port, and relative path

/^ (?: chapter| section) [Location of the 1-9][0-9]{0,1}$/positioning chapter

/[-a-z]/A to Z a total of 26 letters plus one-number.

/ter\b/can match chapter, not terminal

/\bapt/ can match Windows95 or Windows98 or WindowsNT, and when a match is found, start the next time from behind Windows

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.