

- 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 does “?:” mean in a Python regular expression?
Non capturing groups
If we do not want a group to capture its match, we can write this regular expression as Set(?:Value). The question mark and the colon after the opening parenthesis are the syntax that creates a non-capturing group.
The regex Set(Value)? matches Set or SetValue. In the first case, the first (and only) capturing group remains empty. In the second case, the first capturing group matches Value. The question mark appearing at the end is the quantifier that makes the previous token optional.
Set(?:Value) matches Setxxxxx, i.e., all those strings starting with Set but not followed by Value. Such would be non capturing groups.
color=(?:red|green|blue) is another regex with a non-capturing group. This regex has no quantifiers.
Regex flavors that support named capture often have an option to turn all unnamed groups into non-capturing groups.
- Related Questions & Answers
- What does “javascript:void(0)” mean?
- Regular expression “[X?+] ” Metacharacter Java
- What does “dereferencing” a pointer mean in C/C++?
- What does “unsigned” in MySQL mean and when to use it?
- MongoDB regular expression to fetch record with specific name “John”, instead of “john”
- What does the “yield” keyword do in Python?
- How does [\d+] regular expression work in Python?
- How does \B regular expression work in Python?
- What is a regular expression in Python?
- Does Python have “private” variables in classes?
- What does a “set+0” in a MySQL statement do?
- Python Object Comparison “is” vs “==”
- How does BackReference work with Python Regular Expression with Unicode?
- Does it make sense to use “LIMIT 1” in a query “SELECT 1 …”?
- Regular Expression Examples in Python