while doing asian beauty pictures
I have learned more modes in the front, including forward search, backward search, positive mode, and negative mode. This time I will learn another one, which is the backward search positive mode, which means that the string that has been scanned, and I want to regret it to see if it can be matched. Its syntax is: (?<=pattern). For example, the following example is used to identify Twitter accounts, but this pattern will only match and will not appear in the matching string, as follows:
- #python 3.6
- #Cai Junsheng
- # http://www.meimei689.com
- #
- import re
- twitter = re.compile(
- '''''
- # A twitter handle: @username
- (?<=@)
- ([\w\d_]+) # username
- ''',
- re.VERBOSE)
- text = '''''This text includes two Twitter handles.
- One for @caimouse, and one for the author, @caijunsheng.
- '''
- print(text)
- for match in twitter.findall(text):
- print('Handle:', match)
The resulting output is as follows:
This text includes two Twitter handles.
One for @caimouse, and one for the author, @caijunsheng.