-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path57.regularexpression.py
More file actions
29 lines (23 loc) · 855 Bytes
/
57.regularexpression.py
File metadata and controls
29 lines (23 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Regular Expressions In Python
"""
# A RegEx, or Regular Expression, is a sequence of characters that forms a search pattern.
# RegEx can be used to check if a string contains the specified search pattern.
# Python has a built-in package called re, which can be used to work with Regular Expressions.
# When you have imported the re module, you can start using regular expressions:
#
"""
import re
txt = "This Is My First1 Training, 22 This Is Python3 RegEx"
check = re.search("^This.*RegEx$",txt)
if (check):
print("match")
print(re.split('Is|This', txt))
print(re.findall('This', txt))
print(re.sub('My', 'Our', txt))
print(re.findall('\d', txt))
print(re.findall('\W', txt))
print(re.findall('[Ex]', txt))
print(re.findall('[^0-9]+', txt))
print(re.findall('[^a-zA-Z]+', txt))
else:
print("no match")