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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:01:09+00:00 2026-05-16T12:01:09+00:00

I am trying to come up with a GNU extended regular expression that detects

  • 0

I am trying to come up with a GNU extended regular expression that detects repeated substrings in a string of ascii-encoded bits. I have an expression that works — sort of. The problem is that it executes really slowly when given a string that could have many solutions

The expression

([01]+)(\1)+

compiles quickly, but takes about a minute to execute against the string

1010101010101010101010101010101010101010101010101010101010

I am using the regex implementation from glibc 2.5-49 ( comes with CentOS 5.5.)

FWIW, the pcre library executes quickly, as in gregexp or perl directly. So the obvious, but wrong, answer is “use libpcre”. I cannot easily introduce a new dependency in my project. I need to work within the std C library that comes with CentOS/RHEL.

  • 1 1 Answer
  • 2 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-16T12:01:09+00:00Added an answer on May 16, 2026 at 12:01 pm

    If the input string can be of any considerable length, or if performance is at all a concern, then one of the better ways to solve this problem is not with regex, but with a more sophisticated string data structure that facilitates these kinds of queries much more efficiently.

    Such a data structure is a suffix tree. Given a string S, its suffix tree is essentially the Patricia trie of all of its suffixes. Despite its seeming complexity, it can be built in linear time.

    Suffix tree for BANANA Suffix tree for "BANANA"(courtesy of Wikipedia)

    You can do many kinds of queries really efficiently with a suffix tree, e.g. finding all occurences of a substring, the longest substring that occurs at least twice, etc. The kind of strings that you’re after is called tandem repeats. To facilitate this query you’d have to preprocess the suffix tree in linear time so you can do lowest common ancestor queries in constant time.

    This problem is very common in computational biology, where the DNA can be viewed as a VERY long string consisting of letters in ACGT. Thus, performance and efficiency is of utmost importance, and these very sophisticated algorithms and techniques were devised.

    You should look into either implementing these techniques from scratch for your binary sequence, or perhaps it’s easier to map your binary sequence to a “fake” DNA string and then using one of the many tools available for gene research.

    See also

    • Wikipedia/Tandem repeats
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to come up with a regular expression that will match open and
I'm trying to come up with a regular expression that can match only characters
I'm trying to come up with a way combine two arrays that have different
I'm trying to come up with a regular expression which will search for a
I'm trying to come up with an algorithm that will do the following: If
I'm trying to come up with a good naming convention for boolean variables that
I am trying to come up with a Reg Ex that finds the numbers
I'm trying to come up with an answer to two questions that didn't seem
I'm trying to come up with the largest possible group of friends that would
Currently trying to come up with a best practice for a ZF site that

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.