![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
What are negated character classes that are used in Python regular expressions?
We come across negated character classes in Python regular expressions.
An regex of ‘[abdfgh]’ matches any single character which is one of ‘a’, ‘b’, ‘d’, ’f’, ’g’ or ‘h’. This is termed a character class.
An regex of ‘[^abdfgh]’ will match any single character which is NOT one of ‘a’, ‘b’, ‘d’, ’f’, ’g’ or ‘h’. This is a negated character class, and is indicated by the ‘^’ character at the start of the character class.
The character ‘^’ has a special meaning at the start of the character class. if it is used elsewhere in that character class it simply means a ‘^’ character.
Negated character classes work with any of the character classes :
The ranges [0–9] match a single digit character, [^0–9] matches any single character that isn’t a digit.