Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
Regular Expression to filter MAC ADDRESS

I am struck in writing regular expression for below format XXXXXXG0-XXXX-XXXX-1923-785FEABCD128 Above format is to filter MAC Address, so i need those MAC ADDRESS which has the characters defined in the above format and length

Is it possible to write regexp for above format? X characters can be alphanumeric. But other non X characters should be same.

ABCDEFG0-GHYD-SDER-1923-785FEABCD128 - Valid

ABCDEFH0-GHYD-SDER-0923-995FEABCD120 - Invalid

ABCDEFG0-GHYD-SDER-0923-995FEABCD120 - Invalid
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

^[a-zA-Z0-9]{6}G0-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-1923-785FEABCD128$

Explanation:

^ matches beginning of the string

[a-zA-Z0-9]{6} matches any alphanumeric character 6 times

G0- matches that text exactly

[a-zA-Z0-9]{4}- any alphanumeric character 4 times followed by a hyphen (appears twice)

1923-785FEABCD128 matches that text exactly

$ matches the end of the string

about 4 years ago · Juan Pablo Isaza Denunciar

0

import re

patt = re.compile('[A-Z0-9]{6}G0-[A-Z0-9]{4}-[A-Z0-9]{4}-1923-785FEABCD128')

for test in ['ABCDEFG0-GHYD-SDER-1923-785FEABCD128', 'ABCDEFH0-GHYD-SDER-0923-995FEABCD120', 'ABCDEFG0-GHYD-SDER-0923-995FEABCD120']:
    if patt.match(test):
        print(f'{test} - Valid')
    else:
        print(f'{test} - Invalid')

prints

ABCDEFG0-GHYD-SDER-1923-785FEABCD128 - Valid
ABCDEFH0-GHYD-SDER-0923-995FEABCD120 - Invalid
ABCDEFG0-GHYD-SDER-0923-995FEABCD120 - Invalid
about 4 years ago · Juan Pablo Isaza Denunciar

0

For the sake of string-matching instead of a regex, you could use this solution:

mac_addresses = [
    'ABCDEFG0-GHYD-SDER-1923-785FEABCD128',
    'ABCDEFH0-GHYD-SDER-0923-995FEABCD120',
    'ABCDEFG0-GHYD-SDER-0923-995FEABCD120'
]

for address in mac_addresses:
    # splits 3 times, leaving the last two groups together
    # for easier string matching
    first, *_, last = address.split('-', 3)
   
    if first.endswith('G0') and last == '1923-785FEABCD128':
        match = 'Valid'
    else:
        match = 'Invalid'

    print(f"{address} - {match}")

Which prints

ABCDEFG0-GHYD-SDER-1923-785FEABCD128 - Valid
ABCDEFH0-GHYD-SDER-0923-995FEABCD120 - Invalid
ABCDEFG0-GHYD-SDER-0923-995FEABCD120 - Invalid

The benefit here? If you need to change conditions or add a new condition, you don't need to modify/keep up with a regex

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda