-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreModule.py
More file actions
74 lines (55 loc) · 1.64 KB
/
Copy pathreModule.py
File metadata and controls
74 lines (55 loc) · 1.64 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import re # re stands for regular expressions (regex).
'''
Identifiers: # These are the base rules or syntax for a specific expression(word, number, character, space, etc)
\d any number.
\D anything except a number.
\s space.
\S anything except a space.
\w any character.
\W anything except a space.
. anything except a new line.
\b the whitespace around words
\. a .(period).
Modifiers: Description for identifiers.
{1, 3} we're expecting a length of 1 to 3, maybe of a word or a digit, only matter is that it's length will be b/w 1 to 3.
+ Match 1 or more.
? Match 0 or 1.
* Match 0 or more.
$ Match the end of a string.
^ Match the beginning of a string.
| OR
[] Range or variance, ex. [1-5a-qA-Z]
[x] expecting "x" amount
White space characters:
\n new line
\s space
\t tab
\e escape
\f form feed
\r return
Do'nt forget! :
. + * ? [ ] $ ^ ( ) { } | \
To use the above symbols, you always have to escape them from regex
'''
exampleString = '''
Nirbhey's greetings to the reader(s), my age is 21 years,
my mother Manveen is 56 years old and my sister Jessica is 24 years old,
my wife Vidhi is 20 years old, my wish is that each of the Pahwa family members lives more than 100 years of age.
'''
varAges = re.findall(r'\d{1,3}', exampleString)
varNames = re.findall(r'[A-Z][a-z]*', exampleString)
#print(varAges)
#print(varNames)
pahwaDict = {}
x = 0
for i in varNames:
pahwaDict[varNames[x].lower()] = varAges[x]
x += 1
#print(pahwaDict)
x = str(input('Which Pahwa family member \'s age do you want to know?' )).lower()
print(x. upper(),'\'s age is: ', pahwaDict[x])
try:
re.compile(".*+")
print("True")
except Exception as e:
print("False")