-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathregular_expression.py
More file actions
39 lines (25 loc) · 1005 Bytes
/
regular_expression.py
File metadata and controls
39 lines (25 loc) · 1005 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
30
31
32
33
34
35
36
37
38
39
import re
#re is the regular expression python lib
#Check if the string has any 'a' characters:
txt = "Ashika"
print(re.findall("[a]",txt))
#Check if the string has any 'aeiou' characters:
txt = "Do the best you know"
print(re.findall("[aeiou]",txt))
#Check if the string has any characters between a and h:
print(re.findall("[a-h]",txt))
#Check if the string has other characters than p,r,m:
txt = "programming is a superpower"
print(re.findall("[^prm]",txt))
#Check if the string has number 01-39
num = "12"
num2 = "56"
print(re.findall("[0-3][1-9]",num))
print(re.findall("[0-3][1-9]",num2)) #it will show empty which means no matching sequence
#Check if the string has any characters from a to z (lower case)
txt = "A Progrmmer Is Not a Successful At All"
print(re.findall("[a-z]",txt))
#Check if the string has any characters from A to Z (Upper case)
print(re.findall("[A-Z]",txt))
#Check if the string has any characters between a to z and A to Z :
print(re.findall("[a-zA-Z]",txt))