Questions about regular expression reverse reference

Source: Internet
Author: User
For new users, please refer to the following questions about reverse reference of regular expressions: Hello, everyone! I'm a Cainiao. I have something to ask.

I recently read "Let's talk about PHP" and read it in a book. each subexpression in a regular expression (included in ), when no non-capturing metacharacters are added, they are stored in the buffer according to the matching results of each sub-expression from left to right and referenced by numbers \ 1 to \ 99, I don't know if this is the correct description. There are two problems:
1. The book says that using a serial number to reference a subexpression requires a backslash before the serial number to escape the subexpression. This article is very tangled and I don't need it. is it related to any version?
2. is a subexpression added with a metacharacter? :. In this way, the matching results will not be stored, so the number of the buffer will not be added, and no number can be referenced. can this subexpression be called repeatedly?

Thank you!


Reply to discussion (solution)

Let's give an example.No.

Thanks to the moderator for replying. In PHP, I use preg_match for matching. the pattern is '^ ([a-zA-Z] *) \ d + \ 1 $ ', to match the 'demo123demo' string with letters, numbers, and letters, return yes. If a backslash is added before the number in the mode, false is returned.
I tried it myself. Then I have Baidu's several "reference manuals for regular expressions". I do not need to add them in some examples.
Attachment link (do not know whether the Post link will violate the posting code): https://translate.google.com.hk /? Hl = zh-CN & tab = wT, which does not exist in the example.
Okay. I just want to extend this question to see if there is a "version difference". what I really want to answer urgently is the second question, which is bothering the moderator!

What does repeated call and reference mean? If so, do you know the answer.

/^ ([A-zA-Z] *) \ d + \ 1 $/
This is notAdd backslash escape before the number?

Is that what you mean by the second question?
/^ (? = [A-zA-Z] +) \ d + (? = [A-zA-Z] +) $/

Haha, then you will understand. We are honored that both moderators have come out.
The first one is used to escape the backslash. the numbers written in the book I read are \ 1 to \ 99. I need to add a backslash when referencing it, that is, '\ 1'. the instance in the book is like this. I felt wrong last night and found that adding a backslash matches the string' \ 1 '. It seems that books cannot be fully written.
Thank you very much!

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.