You can use the re.split function with the re.IGNORECASE flag (or re.I for short):

>>> import re
>>> test = "hI MY NAME iS FoO bar"
>>> re.split("foo", test, flags=re.IGNORECASE)
['hI MY NAME iS ', ' bar']
>>>
Answer from user2555451 on Stack Overflow
🌐
Finxter
blog.finxter.com › home › learn python blog › python split string case insensitive
Python Split String Case Insensitive - Be on the Right Side of Change
November 22, 2022 - ✨Summary: Use the re.split function of the regex module to split the string using the given delimiter and set the regex flag re.IGNORECASE to ensure a case-insensitive split. Minimal Example Problem Formulation 📜Problem: Given a string containing a mixed blend of uppercase and lowercase ...
Discussions

Python regex split case insensitive in 2.6 - Stack Overflow
I have the following code that works in Python 2.7: entry_regex = '(' + search_string + ')' entry_split = re.split(entry_regex, row, 1, re.IGNORECASE) I need to make it work in Python 2.6 as well ... More on stackoverflow.com
🌐 stackoverflow.com
January 25, 2012
Case insensitivity in Python strings - Stack Overflow
I know that you can use the ctypes library to perform case insensitive comparisons on strings, however I would like to perform case insensitive replacement too. Currently the only way I know to do ... More on stackoverflow.com
🌐 stackoverflow.com
python - Case insensitive replace - Stack Overflow
What's the easiest way to do a case-insensitive string replacement in Python? More on stackoverflow.com
🌐 stackoverflow.com
Check if case sensitive with python (with boolean)
Well, in general it's case sensitive by default. So you can do first check if the word is in a sentence, and it'll only match when it's case sensitive. Then you can convert both to lowercase letters only and check if the lower case version of the word is in the lower case version of the sentence. Since you want to do only one with a boolean check, try: case_sensitive = True if case_sensitive: #do casesensitive check else: #do lowercase check If you don't want it to be part of another word, i guess it's a bit harder. But you can convert the sentence to a list with .split() and then check if it's in that list, since that will be on a word by word basis. Edit: And also remove punctuation and such. More on reddit.com
🌐 r/learnpython
9
1
October 15, 2017
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-case-insensitive-string-replacement
Case insensitive string replacement in Python - GeeksforGeeks
July 23, 2025 - Explanation: re.sub(r"(?i)best", lambda m: "good", a) uses a case-insensitive regex ((?i) inline flag) to match the word "best" in any casing within the string a, and replaces each match using a lambda function that returns "good".
🌐
TutorialsPoint
tutorialspoint.com › article › case-insensitive-string-replacement-using-python-program
Case-insensitive string replacement using Python Program
January 27, 2023 - import re input_string = "Hello TutorialsPOINT Python" substring = "tutorialspoint" replace_string = "Java" # use (?i) for case-insensitive matching result = re.sub('(?i)' + re.escape(substring), replace_string, input_string) print("Result:", result) ... input_string = "Hello TutorialsPOINT Python" substring = "tutorialspoint" replace_string = "Java" words = input_string.split() result_words = [] for word in words: if word.lower() == substring.lower(): result_words.append(replace_string) else: result_words.append(word) result = " ".join(result_words) print("Result:", result)
🌐
Medium
medium.com › @techclaw › python-split-a-comprehensive-guide-3aec8d589806
Python Split: A Comprehensive Guide | by TechClaw | Medium
September 19, 2023 - No, Python split is not case-sensitive. It treats characters in a case-sensitive manner by default. Can I split a string into more than two parts?
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations — Python 3.14.7 ...
Return None if the string does not match the pattern; note that this is different from a zero-length match. The expression’s behaviour can be modified by specifying a flags value.
Find elsewhere
🌐
Mimo
mimo.org › glossary › python › string-split-method
Learn Python's String Split Method, Simplify Text Processing
Python · Open in MimoOpen in MimoCopy Code · import re text = "word1,word2.word3" parts = re.split(r'([,.])', text) print(parts) # Outputs: ['word1', ',', 'word2', '.', 'word3'] The split() method is case-sensitive. For case-insensitive splitting, preprocess the string to a consistent case.
🌐
w3resource
w3resource.com › python-exercises › re › python-re-exercise-44.php
Python: Do a case insensitive string replacement - w3resource
Write a Python function to implement case-insensitive string replacement using regex flags. ... Previous: Write a Python program to split a string at uppercase letters.
🌐
w3resource
w3resource.com › python-exercises › re › python-re-exercise-43.php
Python: Split a string at uppercase letters - w3resource
July 22, 2025 - Write a Python program to split a camelCase string into its constituent uppercase letters. Write a Python script to divide a string at every uppercase letter and output the resulting list. Write a Python program to separate a mixed-case string into segments starting at each uppercase letter.
🌐
Finxter
blog.finxter.com › 5-best-ways-to-perform-case-insensitive-string-replacement-in-python
5 Best Ways to Perform Case Insensitive String Replacement in Python – Be on the Right Side of Change
February 27, 2024 - text = "I love Python, PyThon is great!" pattern = "python" replacement = "Java" result = ' '.join([replacement if word.lower() == pattern.lower() else word for word in text.split()]) print(result) ... I love Java, Java is great! This one-liner utilizes a list comprehension to iterate over the split words of the original string, replacing words that match the pattern (ensured by converting both to lower case) with the replacement, and then joins the words back into a string.
🌐
GeeksforGeeks
geeksforgeeks.org › case-insensitive-string-comparison-in-python
Case-insensitive string comparison in Python - GeeksforGeeks
April 22, 2025 - Explanation: This code uses casefold() for accurate case-insensitive comparison, especially with international characters. It converts all strings, checks uniqueness using a set and prints "equal" if all are identical otherwise, "unequal". re.match() checks if a string matches a pattern from the start and with the re.IGNORECASE flag, it ignores case differences.
🌐
Real Python
realpython.com › lessons › replace-string-python-case-insensitive
Be Case-Insensitive (Video) – Real Python
01:21 Currently, you have global and multi line activated, and that’s why your multiline string works as a test string, but you haven’t selected insensitive so that you look for case-insensitive matches. So once you select it, you will see that the regular expression successfully now finds BLASTED in uppercase or Blast with a uppercase B at the beginning.
Published: August 22, 2023
🌐
Reddit
reddit.com › r/learnpython › check if case sensitive with python (with boolean)
r/learnpython on Reddit: Check if case sensitive with python (with boolean)
October 15, 2017 -

How do I count how many times a case sensitive word appears somewhere using a boolean.

So for example:

word = input("Search this word: ")

Then I want to check if case sensitive == True or False. If it's true, it will only find the exact same words.

Also, the word can't be a part of another word. So it may not find "Apple" in Applepie. But it can only find "Apple" if it's independent like this: Apple Pie

Top answer
1 of 2
2
Well, in general it's case sensitive by default. So you can do first check if the word is in a sentence, and it'll only match when it's case sensitive. Then you can convert both to lowercase letters only and check if the lower case version of the word is in the lower case version of the sentence. Since you want to do only one with a boolean check, try: case_sensitive = True if case_sensitive: #do casesensitive check else: #do lowercase check If you don't want it to be part of another word, i guess it's a bit harder. But you can convert the sentence to a list with .split() and then check if it's in that list, since that will be on a word by word basis. Edit: And also remove punctuation and such.
2 of 2
1
As an aside, you're using the terminology wrong, and in this case, I think it matters and will cause you further confusion along the line if you don't get it clear. I'm not being snarky. It could also be a language thing, as I don't know your native tongue or english dialect, and both of these things can mean we would say things differently. The phrase "Check if case sensitive" doesn't make sense. A word cannot be case sensitive. A program can be case sensitive, that is, it can be sensitive to differences in the upper/lower case letters in a string. A word can be, in Python parlance, lowercase, UPPERCASE, Titlecase or mIxEd case. We say identifiers are in CamelCaps if the first letter of each word in the name is capitalised. I think you are really asking how to control whether a string complarison is case-sensitive or not, and others have ably answered that question. I usually do this by lowercasing everything like this: if case_sensitive_mode and word.lower() in sometext.lower(): # do case insensitive stuff elif word in sometext: # do case sensitive stuff As you want to find distinct words, however, re (regex) is the correct approach. Hope that helps.
🌐
Mathspp
mathspp.com › blog › how-to-work-with-case-insensitive-strings
How to work with case-insensitive strings | mathspp
January 21, 2023 - Short and practical tutorial that guides you on how to work with case-insensitive strings in Python and teaches how to use the str.lower, str.upper, and str.casefold methods.
🌐
LearnPython.com
learnpython.com › blog › python-case-sensitive
Is Python Case-Sensitive? | LearnPython.com
Using the casefold() method is the strongest and the most aggressive approach to string comparison in Python. It’s similar to lower(), but it removes all case distinctions in strings. This is a more efficient way to make case-insensitive comparisons in Python.
🌐
Debugcn
debugcn.com › en › article › 56298357.html
Case Insensitive Python string split() method - DebugCN
I want to retrieve the string before the word feat. or Feat. ... This returns abc. But how can I perform a case insensitive search using split delimiter?