
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 match parentheses in Python regular expression?
The following code matches parentheses in the string s and then removes the parentheses in string s1 using Python regular expression.
Example
import re s = 'I love book()' result = re.search(r'\(\)',s) print result.group() s1 = 'I love book(s)' result2 = re.sub(r'[\(\)]','',s1) print result2
Output
This gives the output
() I love books
- Related Questions & Answers
- How to match a word in python using Regular Expression?
- How to match nonword characters in Python using Regular Expression?
- How to match a whitespace in python using Regular Expression?
- How to match only digits in Python using Regular Expression?
- Explain Python regular expression search vs match
- How to match a single character in python using Regular Expression?
- How to match a nonwhitespace character in python using Regular Expression?
- How to match only non-digits in Python using Regular Expression?
- How to write Python regular expression to match with file extension?
- How to match any one lowercase vowel in python using Regular Expression?
- How to match any one uppercase character in python using Regular Expression?
- How to match any non-digit character in Python using Regular Expression?
- How to use regular expression in Java to pattern match?
- Regular expression to match numbers only in JavaScript?
- How to write a Python regular expression to match multiple words anywhere?
Advertisements