Accumulated Regular Expressions every day (? = X) and (?! X) test (7)

Source: Internet
Author: User
/*. {3 }(? = A) represents a function like this: * Find a substring that matches the first three letters of A in the given string. Of course, the obtained substring does not include (? = A) */pattern P = pattern. Compile (". {3 }(? = )");//(? = X) x, through the zero-width positive lookahead string S1 = "444a66b"; matcher M = P. matcher (S1); While (M. find () {P (M. group ());} P ("***********************************"); /* Similarly \ D {3 }(? = A) indicates a function like this: * search for a substring that matches the first three digits of a. Of course, the obtained substring does not include (? = A) * The 444a66b in this example is matched, and the resulting group is 444 * and "44d4a66b"; it does not match, because there are no consecutive three numbers before a * In example. {3 }(? = B) if the string used to match 444a66b is A66 */P = pattern. Compile ("\ D {3 }(? = )");//(? = X) x, through the zero-width positive lookahead string S2 = "444a66b"; M = P. matcher (S2); While (M. find () {P (M. group ());} P ("***********************************"); (? = X) Let's test and imagine (?! A), the API is interpreted *(?! X) x, through the negative lookahead with Zero Width, it is easy to think of * \ D {3 }(?! A) It indicates that the character after three consecutive numbers is not a match, * therefore, the string 444a666b has only one matched substring: 666 * the string 444b666b matches both the 444 x string 444a666a */P = pattern. compile ("\ D {3 }(?! A )");//(?! X) X, with zero-width negative lookahead string S3 = "444b666b"; M = P. matcher (S3); While (M. find () {P (M. group ());}

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.