You can simply use the guard feature along with capture:

>>>my_str = "iwill/predict_something"
>>>match my_str:
...    case str(x) if 'predict' in x:
...        print("match!")
...    case _:
...        print("nah, dog")
...
match!
Answer from hyp3rg3om3tric on Stack Overflow
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ errors.html
8. Errors and Exceptions โ€” Python 3.14.3 documentation
Note that if the except clauses were reversed (with except B first), it would have printed B, B, B โ€” the first matching except clause is triggered.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-string-comparison
Python Compare Strings - Methods & Best Practices | DigitalOcean
April 17, 2025 - In this article, youโ€™ll learn how each of the operators work when comparing strings. Python string comparison compares the characters in both strings one by one. When different characters are found, then their Unicode code point values are compared.
Discussions

python match case part of a string - Stack Overflow
I want to know if I can use match cases within Python to match within a string - that is, if a string contains the match case. Example: mystring = "xmas holidays" match mystring: c... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python match a string with regex - Stack Overflow
I need a python regular expression to check if a word is present in a string. The string is separated by commas, potentially. So for example, line = 'This,is,a,sample,string' I want to search bas... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python search strings with partial match
string1 = 'First/Second/Third/Fourth/Fifth' string2 = 'Second/Third/SomethingElse/Etc' Is there a native way in Python to search for partial matches stating at any point and ending at any point? In the examples above there is a partial match of 'Second/Third' between the two strings, then I ... More on forum.inductiveautomation.com
๐ŸŒ forum.inductiveautomation.com
1
0
March 9, 2023
Comparing Strings
I am trying to program a Hangman ... order, is there a way to compare the string without a simple โ€˜==โ€™ that would check if the letters match instead of the entire string?... More on discuss.python.org
๐ŸŒ discuss.python.org
0
July 11, 2023
๐ŸŒ
Playwright
playwright.dev โ€บ locators
Locators | Playwright
Method locator.and() narrows down an existing locator by matching an additional locator.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
String Comparison in Python (Exact/Partial Match, etc.) | note.nkmk.me
April 29, 2025 - Search for a string in Python (Check if a substring is included/Get a substring position) Similar to numbers, the == operator checks if two strings are equal. If they are equal, True is returned; otherwise, False is returned. print('abc' == ...
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ subprocess.html
subprocess โ€” Subprocess management
On POSIX with shell=True, the shell defaults to /bin/sh. If args is a string, the string specifies the command to execute through the shell. This means that the string must be formatted exactly as it would be when typed at the shell prompt.
Find elsewhere
๐ŸŒ
KDnuggets
kdnuggets.com โ€บ 5-useful-python-scripts-for-automated-data-quality-checks
5 Useful Python Scripts for Automated Data Quality Checks - KDnuggets
4 days ago - The script uses hash-based exact matching for perfect duplicates, applies fuzzy string matching algorithms using Levenshtein distance for near-duplicates, allows specification of key columns for partial matching, generates duplicate clusters with similarity scores, and exports detailed reports showing all potential duplicates with recommendations for deduplication.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ re.html
re โ€” Regular expression operations
3 days ago - Group names must be valid Python identifiers, and in bytes patterns they can only contain bytes in the ASCII range. Each group name must be defined only once within a regular expression. A symbolic group is also a numbered group, just as if the group were not named. Named groups can be referenced in three contexts. If the pattern is (?P<quote>['"]).*?(?P=quote) (i.e. matching a string quoted with either single or double quotes):
๐ŸŒ
Pydantic
docs.pydantic.dev โ€บ latest โ€บ concepts โ€บ pydantic_settings
Settings Management - Pydantic Validation
The Azure Key Vault source accepts a dash_to_underscore option, disabled by default, to support Key Vault kebab-case secret names by mapping them to Python's snake_case field names.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ string-comparison-in-python
String Comparison in Python - GeeksforGeeks
The == operator is a simple way to check if two strings are identical. If both strings are equal, it returns True; otherwise, it returns False. ... s1 = "Python" s2 = "Python" # Since both strings are identical, therefore it is True print(s1 == s2)
Published ย  July 23, 2025
๐ŸŒ
Medium
sheraz1.medium.com โ€บ mastering-pythons-match-case-a-guide-to-pattern-matching-in-python-3-10-2bd7997dc896
Mastering Pythonโ€™s Match Case: A Guide to Pattern Matching in Python 3.10+ | by Sheraz Ahmad | Medium
January 30, 2025 - If value is 10, the value will be compared with case 10 and it will print "Ten". If value is 20, it will print "Twenty". For any other value, it will print "Something else". The underscore (_) acts as a wildcard, catching any case that isn't explicitly matched.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_regex.asp
Python RegEx
If no matches are found, an empty list is returned: ... The search() function searches the string for a match, and returns a Match object if there is a match.
๐ŸŒ
Python
peps.python.org โ€บ pep-0636
PEP 636 โ€“ Structural Pattern Matching: Tutorial | peps.python.org
Any class is a valid match target, and that includes built-in classes like bool str or int. That allows us to combine the code above with a class pattern. So instead of writing {"text": message, "color": c} we can use {"text": str() as message, ...
๐ŸŒ
Python
peps.python.org โ€บ pep-0622
PEP 622 โ€“ Structural Pattern Matching | peps.python.org
F-strings are not allowed (since in general they are not really literals). ... Only a single name is allowed (a dotted name is a constant value pattern). A capture pattern always succeeds. A capture pattern appearing in a scope makes the name local to that scope. For example, using name after the above snippet may raise UnboundLocalError rather than NameError, if the "" case clause was taken: match greeting: case "": print("Hello!") case name: print(f"Hi {name}!") if name == "Santa": # <-- might raise UnboundLocalError ...
๐ŸŒ
Typesense
typesense.org โ€บ posts โ€บ fuzzy string matching in python (with examples)
Fuzzy string matching in Python (with examples) | Typesense
Like the python-Levenshtein library, it also has a ratio function: from fuzzywuzzy import fuzz str1 = 'But I have promises to keep, and miles to go before I sleep.' str2 = 'But I have many promises to keep, and miles to run before sleep.' ratio = fuzz.ratio(str1, str2) The library also provides advanced functions for handling other complex string matching scenarios.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Comparing Strings - Python Help - Discussions on Python.org
July 11, 2023 - Hello, I am attempting to teach myself Python using MITโ€™s OCW. I am trying to program a Hangman game using functions and I need to compare a string (letters_guessed) to the word the computer chose (secret_word (also a stโ€ฆ