Skip to content

Commit 05d5fc6

Browse files
committed
fix: save lines, add DR codeblock
1 parent e315133 commit 05d5fc6

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

how-to-check-if-a-python-string-contains-a-substring/check_case.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
file_content_title = """Hi There And Welcome.
22
This Is A Special Hidden File With A Secret Secret.
3-
I Don'T Want To Tell You The Secret,
4-
But I Do Want To Secretly Tell You That I Have One.
5-
"""
3+
I Don't Want To Tell You The Secret,
4+
But I Do Want To Secretly Tell You That I Have One."""
65

76
# Strings are case-sensitive
87
print("secret" in file_content_title) # False

how-to-check-if-a-python-string-contains-a-substring/check_substring.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
raw_file_content = """Hi there and welcome.
22
This is a special hidden file with a SECRET secret.
33
I don't want to tell you The Secret,
4-
but I do want to secretly tell you that I have one.
5-
"""
4+
but I do want to secretly tell you that I have one."""
65

76
# Use the membership operator for pythonic membership checks
87
print("secret" in raw_file_content)

how-to-check-if-a-python-string-contains-a-substring/regex_search.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
file_content = """hi there and welcome.
55
this is a special hidden file with a secret secret.
66
i don't want to tell you the secret,
7-
but i do want to secretly tell you that i have one.
8-
"""
7+
but i do want to secretly tell you that i have one."""
98

109
# Find words that start with "secret"
1110
print(re.search(r"secret\w+", file_content))
@@ -21,9 +20,13 @@
2120
# Find all words followed by certain punctuation characters
2221
print(re.findall(r"secret[\.,]", file_content))
2322

24-
# Use a capture group to remove the punctuation character
23+
# Use a capturing group to remove the punctuation character
2524
print(re.findall(r"(secret)[\.,]", file_content))
2625

2726
# Iterate over all matches as Match objects
2827
for match in re.finditer(r"(secret)[\.,]", file_content):
2928
print(match)
29+
30+
# Print only the first capturing group from the match
31+
for match in re.finditer(r"(secret)[\.,]", file_content):
32+
print(match.group(1))

how-to-check-if-a-python-string-contains-a-substring/string_info.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
file_content = """hi there and welcome.
22
this is a special hidden file with a secret secret.
33
i don't want to tell you the secret,
4-
but i do want to secretly tell you that i have one.
5-
"""
4+
but i do want to secretly tell you that i have one."""
65

76
# Use .index() to get the starting index of the first match
87
print(file_content.index("secret"))

0 commit comments

Comments
 (0)