In python, the Backward Search confirmation mode using a regular expression is used. In python, the regular expression is used.

Source: Internet
Author: User

In python, the Backward Search confirmation mode using a regular expression is used. In python, the regular expression is used.

I learned a lot about it, including forward search, Backward Search, positive search, and negative search. Here we will learn one more, that is, the Backward Search validation mode, which means that the string has been scanned, and we want to regret it and see if it can be matched. Its syntax is :(? <= Pattern ). For example, the following example is used to identify the Twitter account. However, this pattern only matches and does not appear in the matched string, as shown below:
 

[Python]View plain copy
  1. # Python 3.6
  2. #
  3. Import re
  4. Twitter = re. compile (
  5. '''''
  6. # A twitter handle: @ username
  7. (? <= @)
  8. ([\ W \ d _] +) # username
  9. ''',
  10. Re. VERBOSE)
  11. Text = ''' This text includes des two Twitter handles.
  12. One for @ caimouse, and one for the author, @ caijunsheng.
  13. '''
  14. Print (text)
  15. For match in twitter. findall (text ):
  16. Print ('handle: ', match)



The output is as follows:
This text includes des two Twitter handles.
One for @ caimouse, and one for the author, @ caijunsheng.

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.