Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f0de22f

Browse files
committed
Initial commit
1 parent d1761bb commit f0de22f

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

‎C7_find_urls.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Find website URLs that begin with http:// or https://.
3+
4+
"""
5+
6+
import pyperclip
7+
import re
8+
9+
url_regex = re.compile('''(
10+
(http:|https:)//
11+
[a-zA-z0-9-/.#_]{4,}
12+
)''', re.VERBOSE)
13+
14+
text = pyperclip.paste()
15+
urls = url_regex.findall(text)
16+
for groups in url_regex.findall(text):
17+
print(groups[0])

‎C7_phones_and_emails.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Find every phone number and email address in a text (from clipboard).
3+
4+
"""
5+
6+
import pyperclip
7+
import re
8+
9+
phoneRegex = re.compile(r'''(
10+
(\d{3}|\(\d{3}\))? # area code
11+
(\s|-|\.)? # separator
12+
(\d{3}) # first 3 digits
13+
(\s|-|\.) # separator
14+
(\d{4}) # last 4 digits
15+
(\s*(ext|x|ext.)\s*(\d{2,5}))? # extension
16+
)''', re.VERBOSE)
17+
18+
emailRegex = re.compile(r'''(
19+
[a-zA-Z0-9._%+-]+ # username
20+
@ # @ symbol
21+
[a-zA-Z0-9.-]+ # domain name
22+
(\.[a-zA-Z]{2,4}) # dot-something
23+
)''', re.VERBOSE)
24+
25+
text = str(pyperclip.paste())
26+
matches = []
27+
for groups in phoneRegex.findall(text):
28+
phoneNum = '-'.join([groups[1], groups[3], groups[5]])
29+
if groups[8] != '':
30+
phoneNum += ' x' + groups[8]
31+
matches.append(phoneNum)
32+
33+
for groups in emailRegex.findall(text):
34+
matches.append(groups[0])
35+
36+
if len(matches) > 0:
37+
pyperclip.copy('\n'.join(matches))
38+
print("Copied to clipboard:")
39+
print('\n'.join(matches))
40+
else:
41+
print("No phone numbers or email addresses found!")

‎C7_remove_whitespaces.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
If no other arguments are passed other than the string to
3+
strip, then whitespace characters will be removed from the beginning and
4+
end of the string.
5+
Otherwise, the characters specified in the second argument
6+
to the function will be removed from the string.
7+
8+
"""
9+
10+
import re
11+
12+
13+
def remove_spaces(string):
14+
start = re.compile(r'^\s*')
15+
end = re.compile(r'\s*$')
16+
string = start.sub('', string)
17+
string = end.sub('', string)
18+
return string
19+
20+
21+
s = " this is a string "
22+
23+
print("This is what I have for you:")
24+
print(remove_spaces(s))

‎C7_strong_password_detection.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Program that uses regular expressions to make sure the password string it is passed is strong.
3+
4+
A strong password is defined as one that is at least eight characters long,
5+
contains both uppercase and lowercase characters,
6+
and has at least one digit.
7+
8+
"""
9+
10+
import re
11+
12+
13+
def is_strong(password):
14+
"""
15+
Function that uses regular expressions to make sure the password string it is passed is strong.
16+
17+
:param password: The password that should be checked
18+
:return: True is password is strong, False otherwise
19+
"""
20+
# at least eight characters long
21+
if len(password) < 8:
22+
return False
23+
24+
# contains both uppercase and lowercase characters
25+
upper = re.compile(r"[A-Z]")
26+
up = upper.search(password)
27+
lower = re.compile(r"[a-z]")
28+
low = lower.search(password)
29+
30+
# has at least one digit
31+
digit = re.compile(r'[0-9]')
32+
dig = digit.search(password)
33+
34+
if up is None or low is None or dig is None:
35+
return False
36+
37+
return True
38+
39+
40+
print("Give a password: ")
41+
password = input()
42+
print("This password is strong: ")
43+
print(is_strong(password))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /