1. Regular matching Chinese characters

import re
str1='HJGGJ little VJJK Ming'
pat=re.compile(r'[\u4e00-\u9fa5]+')
result=pat.findall(str1)
print(result)
# output [' small ', 'Ming ']
Copy the code

2. Re matches numbers

import re
re.findall(r'\d+'.'hello 42 I'm a 32 string 30')
# ['42', '32', '30'] re.findall(r'\d+', "hello 42 I'm a 32 str12312ing 30")
['42', '32', '12312', '30']
Copy the code

This allows strings that are not pure digits to be recognized

Identify pure numbers. If you only need numbers separated by word boundaries (Spaces, periods, commas), you can use \b

re.findall(r'\b\d+\b'."hello 42 I'm a 32 str12312ing 30")
# [' 42 ', '32', '30']
re.findall(r'\b\d+\b'."hello,42 I'm a 32 str12312ing 30")
# [' 42 ', '32', '30']
re.findall(r'\b\d+\b'."hello,42 I'm a 32 str 12312ing 30")
# [' 42 ', '32', '30']
Copy the code