SoFunction
Updated on 2024-11-16

Usage in Python

In python, the re module is integrated into python and can be called by programmers to implement regular matching. This article focuses on regular expressions in python.

():function returns a list containing all matches. Returns all matches of all strings in string with pattern, the return form is an array.

Sample code 1: [print all matches]

import re
 
s = "Long live the people's *"
ret = ('h', s)
 
print(ret)

Run results:

Sample code 2: [If no match is found, return to the empty list]

import re
 
s = "Long live the people's *"
ret = ('USA', s)
 
print(ret)

Run results:

Sample code:

import re
 
s = "/weixin_44799217"
ret = (r"^http", s)
print(ret)
 
ret2 = (r"[t,b,s]", s)  # Matches one of the characters in the brackets
print(ret2)
 
ret3 = (r"\d\d\d", s)
print(ret3)
 
ret4 = (r"\d", s)
print(ret4)
 
ret5 = (r"[^\d]", s)  # Taking the wrong
print(ret5)
 
ret6 = (r"[^https://]", s)  # Taking the wrong
print(ret6)

Run results:

Get the title in the site:

import requests
import re
 
url = '/'
 
response = (url)
data = 
# print(data)
res = (r'<title>(.*?)</title>', data)[0]
print(res)

Running effects:

To this point this article on Python () usage details of the article is introduced to this, more related Python () usage content please search my previous posts or continue to browse the following related articles I hope you will support me in the future more!