Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
Using A Different Regex Engine in Python

Python uses the "Python" regex engine re; this implementation is very slow. I want to try and use the ECMAScript implementation of regex in my python code... is there a way to do this? Here's my regex that finds IPv4 and IPv6 addresses:

(?:(?:(?:[0-9A-Fa-f]{1,4}:){6}[0-9A-Fa-f]{1,4})|(?:[0-9A-Fa-f]{1,4}::(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(?:(?:[0-9A-Fa-f]{1,4}:){2}:(?:[0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(?:(?:[0-9A-Fa-f]{1,4}:){3}:(?:[0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(?:(?:[0-9A-Fa-f]{1,4}:){4}:(?:[0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(?:(?:[0-9A-Fa-f]{1,4}:){5}:(?:[0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(?:(?:[0-9A-Fa-f]{1,4}:){6}:(?:[0-9A-Fa-f]{1,4}:){0}[0-9A-Fa-f]{1,4})|(?:(?:[0-9A-Fa-f]{1,4}:){1,6}[0-9A-Fa-f]{1,4}::)|(?:(?:[0-9A-Fa-f]{1,4})::)|(?:::(?:[0-9A-Fa-f]{1,4}:){1,6})[0-9A-Fa-f]{1,4}|(?:::(?:[0-9A-Fa-f]{1,4})))(?!\:)|(?<!\.)(?:(?<![0-9])(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?![0-9]))(?!\.)

It may be able to be optimized further (suggestions are welcome) but, when I put it into regex101.com with some beefy test data, it becomes quickly apparent that EMCAScript is much faster than the Python version... ECMAScript Flavor Regex finds 21523 matches in 505.2ms

Python Flavor Regex times out

Implementing the Python flavor in Python is as simple as "import re"

What are the steps to implementing the ECMAScript (JavaScript) flavor that is fast enough (505.2ms) to run my code

The Python version takes around 3 seconds to run!

I am trying to implement the ECMAScript version into python

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda