I suggest bookmarking the MSDN Regular Expression Quick Reference

you want to achieve a case insensitive match for the word "rocket" surrounded by non-alphanumeric characters. A regex that would work would be:

\W*((?i)rocket(?-i))\W*

What it will do is look for zero or more (*) non-alphanumeric (\W) characters, followed by a case insensitive version of rocket ( (?i)rocket(?-i) ), followed again by zero or more (*) non-alphanumeric characters (\W). The extra parentheses around the rocket-matching term assigns the match to a separate group. The word rocket will thus be in match group 1.

UPDATE 1: Matt said in the comment that this regex is to be used in python. Python has a slightly different syntax. To achieve the same result in python, use this regex and pass the re.IGNORECASE option to the compile or match function.

\W*(rocket)\W*

On Regex101 this can be simulated by entering "i" in the textbox next to the regex input.

UPDATE 2 Ismael has mentioned, that the regex is not quite correct, as it might match "1rocket1". He posted a much better solution, namely

(?:^|\W)rocket(?:$|\W)

Answer from Xaser on Stack Exchange
🌐
Quora
quora.com › How-do-you-match-an-exact-word-with-Regex-Python
How to match an exact word with Regex Python - Quora
Answer (1 of 10): You said “exact word”, and technically, the regex [code ]r'word'[/code] would get you that. However, I get the impression that might not be what you want, because “turn” and “turning” are different words, and [code ...
🌐
Finxter
blog.finxter.com › how-to-match-an-exact-word-in-python-regex-answer-dont
How to Match an Exact Word in Python Regex? (Answer: Don’t) – Be on the Right Side of Change
So if you’re an impatient person, here’s the short answer: To match an exact string 'hello' partially in 'hello world', use the simple regex 'hello'. However, a simpler and more Pythonic approach would be using the in keyword within membership expression 'hello' in 'hello world'.
🌐
Reddit
reddit.com › r/regex › regex exact match search
r/regex on Reddit: Regex exact match search
March 11, 2022 -

I'm searching for exact word match of the word - "new"
in the string - "This is a new String"
using the regex - /^new$/
But the regex101 does not match anything, what am i missing ?
https://regex101.com/r/o1TBGn/1

🌐
Bytes
bytes.com › home › forum › topic › python
Exact Word Match in String with Regex in Python - Post.Byes
Hello, I've been trying to come up with a way to search for the exact match of one word (as a string) within another string. So, for example, if I were searching for the string, 'eligible', searching it against the string 'ineligible' would not yield a result. Here is the code I have thus far: ... def findstring(string1, string2): if re.search(r'(^|[^a-z0-9])'+re.escape(string1)+r'($|[^a-z0-9])', string2): return True return False This, however, still would match 'ineligible.' What is the regex needed to ensure that only exact words are matched?
🌐
AskPython
askpython.com › home › matching entire strings in python using regular expressions
Matching Entire Strings in Python using Regular Expressions - AskPython
February 27, 2023 - Open a command prompt or terminal ... specified regular expression pattern. To match an exact string, you can simply pass the string as the pattern....
🌐
ZetCode
zetcode.com › python › regularexpressions
Python regular expressions - using regular expressions in Python
The fullmatch function looks an exact match. ... #!/usr/bin/python import re words = ('book', 'bookworm', 'Bible', 'bookish','cookbook', 'bookstore', 'pocketbook') pattern = re.compile(r'book') for word in words: if re.fullmatch(pattern, word): print(f'The {word} matches')
🌐
YouTube
youtube.com › finxter
How to Match an Exact Word in Python Regex? (Answer: Don’t) - YouTube
This morning, I read over an actual Quora thread with this precise question. While there’s no dumb question, the question reveals that there may be some gap ...
Published   March 4, 2020
Views   2K
Find elsewhere
🌐
Mantidproject
docs.mantidproject.org › nightly › tutorials › introduction_to_python › pattern_matching_with_regular_expressions.html
Pattern Matching With Regular Expressions
regex: '[a-z,A-Z,0-9]*' test: 'mm' # Matches test: 'a0123' # Matches · To specify an exact number of characters use braces {}, e.g. regex: 'a{2}' test: 'abab' # Fails as there is not two consecutive a's in the string test: 'aaaab' # Matches
🌐
Predictivehacks
predictivehacks.com
Regular Expression for Exact Match – Predictive Hacks
keyword = "$ 30" keyword = re.escape(keyword) df.loc[df.Document.str.contains(rf"(?<!\w){keyword}(?!\w)", case=False, regex=True)]
🌐
TutorialsPoint
tutorialspoint.com › how-to-match-a-word-in-python-using-regular-expression
How to match a word in python using Regular Expression?
By default, regular expression matching is case-sensitive, which means it will only match words that exactly match the case specified in the pattern. To perform case-insensitive matches, we can use re.IGNORECASE flag. Following is an example that uses the re.IGNORECASE flag in the re.findall() ...
🌐
Python documentation
docs.python.org › 3 › howto › regex.html
Regular Expression HOWTO — Python 3.14.3 documentation
Being able to match varying sets ... on strings. However, if that was the only additional capability of regexes, they wouldn’t be much of an advance. Another capability is that you can specify that portions of the RE must be repeated a certain number of times. The first metacharacter for repeating things that we’ll look at is *. * doesn’t match the literal character '*'; instead, it specifies that the previous character can be matched zero or more times, instead of exactly ...
🌐
Note.nkmk.me
note.nkmk.me › home › python
String Comparison in Python (Exact/Partial Match, etc.) | note.nkmk.me
April 29, 2025 - This article explains string comparisons in Python, covering topics such as exact matches, partial matches, forward/backward matches, and more. Exact match (equality comparison): ==, != Partial match: ...
🌐
sqlpey
sqlpey.com › python › python-regex-exact-words
Python Regex: Locate Exact Words in Strings - sqlpey
July 22, 2025 - Learn how to use Python's `re` module to find whole words within text, avoiding partial matches. Explore solutions using word boundaries and practical code examples.