About 11,100,000 results
Open links in new tab
  1. python - Find substring in string but only if whole words

    The simplest and most pythonic way, I believe, is to break the strings down into individual words and scan for a match: string = "My Name Is Josh" substring = "Name" for word in string.split(): …

  2. python - string match only whole words - Stack Overflow

    Apr 3, 2013 · You could use regexes and the \b word boundaries: import re the_regex = re.compile(r'\b' + r'\b'.join(map(re.escape, ['president', 'pub'])) + r'\b') if the_regex.search(' …

  3. How can I write the whole word of the variable, in Python?

    Jan 21, 2021 · This is for both single word and multiple words, so either you can just print(Answer) or you can first split it by e.g. space and then print each word in a sentence like this: answer = …

  4. Python | Extract words from given string - GeeksforGeeks

    Jul 25, 2023 · Python Extract String Words using List Comprehension . In Python, you can extract words from a string using list comprehension. List comprehension provides a concise and …

  5. Matching Whole Words with Regular Expressions in Python 3

    Jan 18, 2025 · Regular expressions provide a powerful way to match whole words within a larger body of text in Python 3. By using the \b metacharacter, we can ensure that our matches are …

  6. Iterate over words of a String in Python - GeeksforGeeks

    Nov 10, 2024 · In this article, we’ll explore different ways to iterate over the words in a string using Python. Let’s start with an example to iterate over words in a Python string: Explanation: Split …

  7. Extract a specific word from a string in Python

    Mar 31, 2021 · We can use regular expressions in python to extract specific words from a string. We can use search () method from re module to find the first occurrence of the word and then …

  8. How to read a string word by word in Python - PyTutorial

    Jan 13, 2023 · In this article, we have covered different techniques for reading strings word by word in Python, including using the built-in split() method, the re module's split() function, the …

  9. Python – Add Phrase in middle of String - GeeksforGeeks

    May 12, 2023 · Method #1 : Using split () + slicing + join () In this, Strings are converted to a list of words, then the middle position is extracted to append a new phrase. After addition, the string …

  10. Python Strings - W3Schools

    Strings. Strings in python are surrounded by either single quotation marks, or double quotation marks. 'hello' is the same as "hello". You can display a string literal with the print() function:

Refresh