In python, regular expressions are used for Backward Search (recommended) and python regular expressions.

Source: Internet
Author: User

In python, regular expressions are used for Backward Search (recommended) and python regular expressions.

Regular expressions are not part of Python. Regular Expressions are powerful tools used to process strings. They have their own unique syntax and an independent processing engine, which may not be as efficient as the built-in str method, but are very powerful. Thanks to this, in languages that provide regular expressions, the syntax of regular expressions is the same. The difference is that different programming languages support different syntaxes, unsupported syntax is usually not commonly 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 3.6 # Cai junsheng # http://blog.csdn.net/caimouse/article/details/51749579#import retwitter = re. compile (''' # A twitter handle: @ username (? <= @) ([\ W \ d _] +) # username ''', re. VERBOSE) text = ''' This text includes des two Twitter handles. one for @ caimouse, and one for the author, @ caijunsheng. '''print (text) for match in twitter. findall (text): print ('handle: ', match)

The output is as follows:

 This text includes two Twitter handles.One for @caimouse, and one for the author, @caijunsheng.Handle: caimouseHandle: caijunsheng

Summary

The above is a post-recognition search mode that uses regular expressions in python. I hope it will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in time!

Related Article

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.