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 6178251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:25:31+00:00 2026-05-24T00:25:31+00:00

How would you go about calculating / finding the number of operations a regex

  • 0

How would you go about calculating / finding the number of operations a regex takes to match over a given string? I’d like to develop a program that would allow you to rank regexs in order of efficiency.

Also, is it possible to break out of a regex if the number of operations exceeds a given threshold? I’m hoping to turn this into a web app, so I don’t want users entering regexes that could potentially kill the server (if that’s even possible).

Many thanks.

Edit: Just to clarify, I’m referring to the superset of plain regexes that includes backtracking (which is therefore non-linear).

  • 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-05-24T00:25:32+00:00Added an answer on May 24, 2026 at 12:25 am

    The way to find out how many operations it will take to parse a given string is to parse it and count the number of operations. You could do somewhat limited static analysis, but a definitive answer would be tantamount to solving the halting problem.

    Trying to rank expressions for any input is even more complex. Take the expression A[0-9]+

    • The string “A999” will match, and take roughly O(n) time.
    • The string “B943” will immediately fail, taking O(1) time.

    A regular expression parser is fundamentally just a program. It is almost always not possible to say one program is faster than another in general, only for specific input.

    You could try to use static analysis based on some understanding of what the input might be. For example, an expression which can immediately eliminate a large portion of the common inputs might be faster than one which doesn’t. I would say that the only way to do this is to also accept a dataset of expressions with a similar distribution to those being parsed and either do benchmarks [easy] or analysis [hard] using that data.

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

Sidebar

Related Questions

I would like 'about' to route to 'abouts/1' I tried this: match 'about' =>
Given two integers a and b , how would I go about calculating the
How would one go about calculating a date from a day-number in C++? I
I would like to know how I would go about altering the HTML that
How would you go about calculating the amount of months between two arbitrary dates?
How would I go about calculating the average of all the values in a
Given two convex polygons in 2D space, how would you go about constructing the
How would I go about calculating a compound interest rate, so far I have:
How would I go about calculating the size of a web page (url) using
How would I go about calculating the size and starting byte of the data

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.