- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 Python regular expression to get zero or more occurrences within the pattern?
* An asterisk meta-character in a regular expression indicates 0 or more occurrences of the pattern to its left
The following code matches and prints the zero or more occurrences of the pattern '\w' in the string 'chihua huahua'
Example
import re s = 'chihua huahua' result = re.findall(r'\w*', s) print result
Output
This gives the output
['chihua', '', 'huahua', '']
Advertisements