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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:28:30+00:00 2026-06-10T04:28:30+00:00

Consider the following two cases in both of which the string to test will

  • 0

Consider the following two cases in both of which the string to test will contain only the characters ‘a’, ‘t’, ‘g’ and ‘c’ in any combination and can be of arbitrary length. It could have only ‘t’ for example.

  • Test to see if ‘a’ occurs more than 5 times. If the length of the string is 100 and the character ‘a’ appears five times in the first 10 places, regex should not search the remaining string.
  • Test to see if zero or more consecutive ‘a’ occurs only once and the string must not end with ‘a’. Valid example: ggtcccccccctggtaaaatcg, gctgctcgtccttgcttcg, ag. Invalid: a, agatcttgcgt, agtcga.

Now I know how to construct a basic regex to test for both cases but I want to ensure the search is optimized and does not waste unnecessary iterations. In the second point above, agatcttgcgt should terminate as soon as the third character is tested since it breaks the consecutive rule.

Any help with the optimized regex would help. Also, not the primary question but how can I see th internals of how the search is performed (number of iterations, etc.)?

  • 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-10T04:28:31+00:00Added an answer on June 10, 2026 at 4:28 am

    If performance is critical you might want to consider non-regex solutions. For example your first requirement can easily be solved by using string.Contains.

    A regular expression typically scans its input in a linear fashion from left to right, looking at every character until it finds a match, and possibly looking at characters multiple times if there is backtracking. On the other hand, there exist some advanced string searching algorithms that can determine the presence or absence of a substring without necessarily examining all characters in the string. For example, to search for aaaaa you only need to check every fifth character until you find an a.

    Also, not the primary question but how can I see th internals of how the search is performed (number of iterations, etc.)?

    You can use RegexBuddy to debug regular expressions and to see how many steps are needed:

    RegexBuddy: debugging a regex

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

Sidebar

Related Questions

Consider the following two Java files that contain a simplified version of my issue
Consider the following situation: We have two Localizable.string files, one in en.lproj and one
Consider the following situation: I have two android projects named P1 and P2 which
Consider the following two Java classes: a.) class Test { void foo(Object foobar) {
Consider the following two lines of code if (test ! = null) and if
Consider the following two fragments of code: scala> def f1(x:Any) = x match {
Today, I've stumbled over the following: Consider two classes NewClass and NewClass1, which have
Consider the following: I have two tables (Customers and Cases) defined as follows: **Customers**
Consider the following two EXPLAINs: EXPLAIN SELECT * FROM sales WHERE title != 'The'
Consider the following two toolbars that are in the same project of mine: Notice

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.