Backreference a reverse reference in an Oracle regular expression

Source: Internet
Author: User

This is the description of Oracle's backreference of regular expressions

As you can see from the definition, a substring is included in the form of () in the matching expression, and can be referenced in the form of \? later. \1 corresponds to the first (), \2 corresponds to the second ...

The introduction of reverse references makes the matching function of regular expressions more powerful and introduces two applications in Oracle regular functions

Regexp_like

Regexp_like (' 1211233 ', ' ^ ([0-9]) (\d) \1\1\2 (\d) \3$ ')

In this example, in the match expression, \1 represents the first ([0-9]), which determines whether the 3rd, 4 digits in the string are the same as the 1th bit, not just the match [0-9].

Regexp_replace

Regexp_replace (' 1234567 ', ' ^ (.) (.) (.) (.) (.) (.) ', ' \1\2\5 ')

Here, replace the part in the matching expression with the content that satisfies \1\2\5, the first (.) A second (.) and a fifth (.)

Guess what's going to come back here?

Because ^ (.) (.) (.) (.) (.) (.) Matches the first 6 bits of the string, so the result is \1\2\5| | After the 6th bit, that is, 1257

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.