- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 character class operations in Python?
Some regular expression engines allow some fancy operations within character classes. We can match characters that belong to one class but not to another (subtraction); match characters that belong both to one class and another (intersection), or match characters that belong to either of several classes (union).
The re module in Python, allows us to use the AND operator && to specify the intersection of multiple classes within a character class: […&&[…]]specifies a character class representing the intersection of two sub-classes—meaning that the character matched by the class must belong to two sub-classes. For instance, [\S&&[\D]] specifies one character that is both a non-whitespace character and a non-digit.
Character Class Subtraction in the re module for Python
For instance, the class
[a-z--[aeiou]]matches an English lower-case consonant.
In addition, when the subtracted class does not include a range, its brackets are optional. The above can therefore also be written as [a-z--aeiou]
Character class union in the re module for Python
In the re module for Python, to create the union of multiple character classes, we use the OR operator ||. For instance, [0||[^\W\d]] specifies a character that is either 0 or a word character that is not a digit.
- What are the FTP Operations?
- What are Arithmetic Micro-operations?
- What are file operations in C#?
- What are file operations in Java?
- What are character classes or character sets used in Python regular expression?
- What are built-in class attributes in Python?
- What are the operations on process?
- What are memory operations in C language?
- What are static methods in a Python class?
- What are ActionChains class in Selenium with python?
- Explain the Character operations in C language
- Character Class in Java
- What are negated character classes that are used in Python regular expressions?
- What are C++ Character Constants?
- What are Character Entities in HTML5