- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to write a Python regular expression to match multiple words anywhere?
The following code using Python regex matches the given multiple words in the given string
Example
import re s = "These are roses and lilies and orchids, but not marigolds or .." r = re.compile(r'\broses\b | \bmarigolds\b | \borchids\b', flags=re.I | re.X) print r.findall(s)
Output
This gives the output
['roses', 'orchids', 'marigolds']
- Related Articles
- How to write Python regular expression to match with file extension?
- How to write a regular expression to match either a or b in Python?
- How to match parentheses in Python regular expression?
- How to write JavaScript Regular Expression for multiple matches?
- How to match a word in python using Regular Expression?
- How to match a whitespace in python using Regular Expression?
- How to match a nonwhitespace character in python using Regular Expression?
- How to match a single character in python using Regular Expression?
- How to write a Python regular expression to use re.findall()?
- How to write a Python Regular Expression to validate numbers?
- How to match nonword characters in Python using Regular Expression?
- How to match only digits in Python using Regular Expression?
- How to match a regular expression against a string?
- How do we use Python regular expression to match a date string?
- How to match only non-digits in Python using Regular Expression?

Advertisements