Except for the capture group syntax, other (?...) The syntax is not the verification of the capture group.

Source: Internet
Author: User

Except for the capture group syntax, other (?...) The syntax is not the verification of the capture group.

See the following content in a regular expression technical document:

"It must be noted that apart from (Expression) and (? <Name> Expression) syntax, other (?...) Neither of the syntax is a capture group ."
This content is understandable, but I am confused that the author of this article, in another technical article on related regular expressions, is an example of this, which really puzzles me:

Text Content

<td>a</td><td>b</td> 

Regular Expression

(?is)<td>(?:(?!</td>).)*</td> 

Pay attention to the code of the regular expression above. </Td>). "force a non-capturing group. I told him in the text message that it could be written as follows :(? Is) <td> ((?! </Td>).) * </td>
Two days later, I still didn't see him reply, so I looked back at his code. At first I focused on "(?! </Td>) "This bracket is not a capture group. However, I only reflected the code in the above technical article once. He is not targeting (?! </Td>) force (?! </Td>). The force is not a capture group, so I did the following test:

Text Content

<td>a</td><td>a</td>

Regular Expression

<td>((?!</td>).)*</td><td>(\1)*</td>

Matching result

<td>a</td><td>a</td>

This proves that, if not, "(?! </Td>). "to force a non-capturing group, it will be captured, and I don't need it at all.
Next, I'm testing, except (Expression) and (? <Name> Expression) except the syntax, for example, loop view, it is not a capture group.

Text Content

<td>a</td><td>a</td> 

Regular Expression

<td>((?!</td>).)*</td><td>(\2.)*</td>

Matching result: Mismatch
If you have different opinions, please discuss them.

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.