Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:09:10+00:00 2026-06-04T15:09:10+00:00

Below is the Python regular expression. What does the ?: mean in it? What

  • 0

Below is the Python regular expression. What does the ?: mean in it? What does the expression do overall? How does it match a MAC address such as “00:07:32:12:ac:de:ef“?

re.compile(([\dA-Fa-f]{2}(?:[:-][\dA-Fa-f]{2}){5}), string)  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:09:12+00:00Added an answer on June 4, 2026 at 3:09 pm

    It (?:...) means a set of non-capturing grouping parentheses.

    Normally, when you write (...) in a regex, it ‘captures’ the matched material. When you use the non-capturing version, it doesn’t capture.

    You can get at the various parts matched by the regex using the methods in the re package after the regex matches against a particular string.


    How does this regular expression match MAC address "00:07:32:12:ac:de:ef"?

    That’s a different question from what you initially asked. However, the regex part is:

    ([\dA-Fa-f]{2}(?:[:-][\dA-Fa-f]{2}){5})
    

    The outer most pair of parentheses are capturing parentheses; what they surround will be available when you use the regex against a string successfully.

    The [\dA-Fa-f]{2} part matches a digit (\d) or the hexadecimal digits A-Fa-f], in a pair {2}, followed by a non-capturing grouping where the matched material is a colon or dash (: or -), followed by another pair of hex digits, with the whole repeated exactly 5 times.

    p = re.compile('([\dA-Fa-f]{2}(?:[:-][\dA-Fa-f]{2}){5})')
    m = p.match("00:07:32:12:ac:de:ef")
    if m:
        m.group(1)
    

    The last line should print the string "00:07:32:12:ac:de" because that is the first set of 6 pairs of hex digits (out of the seven pairs in total in the string). In fact, the outer grouping parentheses are redundant and if omitted, m.group(0) would work (it works even with them). If you need to match 7 pairs, then you change the 5 into a 6. If you need to reject them, then you’d put anchors into the regex:

    p = re.compile('^([\dA-Fa-f]{2}(?:[:-][\dA-Fa-f]{2}){5})$')
    

    The caret ^ matches the start of string; the dollar $ matches the end of string. With the 5, that would not match your sample string. With 6 in place of 5, it would match your string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is some sample code. The window does not resize (python3.2, on a Mac,
System: Mac OSX 10.6.5, Python 2.6 I try to run the python script below:
I'm trying to compile a python program using jython and it's throwing below error
I'm extracting portions of URLs from text using a regular expression in Python. The
I want to validate below data using regex and python. Below is the dump
I have a python psp page code is shown below. Currently it only prints
The example below is from a REST database driver on Python 2.7. In the
I am working with python plugins.I used list to store some values as below:
I have a python script which outputs lots of data, sample is as below.
In the code shown below, I need to manipulate the time var in python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.