
- 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 use special characters in Python Regular Expression?
From Python documentation
Non-special characters match themselves. Special characters don't match themselves −
\ | Escape special char or start a sequence. |
. | Match any char except newline, see re.DOTALL |
^ | Match start of the string, see re.MULTILINE |
$ | Match end of the string, see re.MULTILINE |
[ ] | Enclose a set of matchable chars |
R|S | Match either regex R or regex S. |
() | Create capture group, & indicate precedence |
After '[', enclose a set, the only special chars are −
] | End the set, if not the 1st char |
- | A range, eg. a-c matches a, b or c |
^ | Negate the set only if it is the 1st char |
Quantifiers (append '?' for non-greedy) −
{m} | Exactly m repetitions |
{m,n} | From m (default 0) to n (default infinity) |
* | 0 or more. Same as {,} |
+ | 1 or more. Same as {1,} |
? | 0 or 1. Same as {,1} |
- Related Questions & Answers
- How to escape any special character in Python regular expression?
- Regular Expression Special Variables in Perl
- How to use wildcard in Python regular expression?
- How to use range in Python regular expression?
- How to use variables in Python regular expression?
- How to match nonword characters in Python using Regular Expression?
- How to write Python regular expression to check alphanumeric characters?
- Write a Regular Expression to remove all special characters from a JavaScript String?
- How to write Python Regular expression to remove non unicode characters?
- How to write a Python regular expression to use re.findall()?
- How to use Unicode and Special Characters in Tkinter?
- How do we use Python Regular Expression named groups?
- How to split on successions of newline characters using Python regular expression?
- MySQL regular expression to update a table with column values including string, numbers and special characters
- How do we use re.finditer() method in Python regular expression?
Advertisements