

- 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
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.
- Related Questions & Answers
- What are repeating character classes used in Python regular expression?
- What are character classes or character sets used in Python regular expression?
- What are metacharacters inside character classes used in Python regular expression?
- Explain character classes in Java regular expressions
- What are regular expressions in C#
- What are regular expressions in JavaScript?
- What are some basic examples of Python Regular Expressions?
- What are anchors in regular expressions in C#?
- What are the regular expressions to finite automata?
- What are the properties of Regular expressions in TOC?
- What are the Rules of Regular Expressions in Compiler Design?
- Character class: intersection - Java regular expressions
- Character class: subtraction - Java regular expressions
- Character class: Negation - Java regular expressions
- Character class: range - Java regular expressions