![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 a regular expression to match either a or b in Python?
The following code uses a regular expression '(a|b)' to match a or b in the given Python string.
We are also using the flag re.I to ignore case of a or b while matching.
Example
import re s = 'Bank of Baroda' print(re.findall(r'(a|b)',s, re.I))
Output
This gives the output
['B', 'a', 'B', 'a', 'a']
Advertisements