forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharClasses.py
More file actions
15 lines (13 loc) · 811 Bytes
/
CharClasses.py
File metadata and controls
15 lines (13 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import re
# search method
print("Character class([]) (1) : ",re.search(r'[Pp]ython','Python'))
print("Character class([]) (2) : ",re.search(r'[a-z]way','The end of the highway'))
print("Character class([]) (3) : ",re.search(r'[a-z]way','What a way to go'))
print("Character class([]) (4) : ",re.search(r'cloud[a-zA-z0-9]','cloud9'))
print("Character class([]) (5) : ",re.search(r'[^a-zA-z]','This is a sentence with spaces.'))
print("Character class([]) (6) : ",re.search(r'[^a-zA-z ]','This is a sentence with spaces.'))
print("Pipe (OR) (1) : ",re.search(r'cat|dog','I like cats.'))
print("Pipe (OR) (2) : ",re.search(r'cat|dog','I like dogs.'))
print("Pipe (OR) (3) : ",re.search(r'cat|dog','I like dogs and cats.'))
# findall method
print("Pipe (OR) (4) : ",re.findall(r'cat|dog','I like dogs and cats.'))