Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!