Read Regular Expression Proficiency: First selects the leftmost matching result

Source: Internet
Author: User

Regular character:Fat | cat | belly | your

Characters to be tested:The dragging belly, indicates your cat is too fat

The first matching result is not "fat ".
", But" belly
".

Regular Expressions can also match fat and other possibilities, but they are not the first matching results (except the leftmost results), so they are not selected. All regular expressions may be tried before the next round. That is to say, before moving, fat, Cat, belly, and your must be tried.

By using regexbuddy debugging, we can see that (the language is Java), the Regular Expression Engine first matches the fat to the first letter "T", and fails, backtracing, and then obtains
CAT does not match, but does not succeed.
If none of them match, the system moves forward. Try the second letter, and so on until "belly" is used to match the word "belly". The match is successful.


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.