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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:18:22+00:00 2026-05-13T07:18:22+00:00

I’ve been stuck trying to write this regular expression I need. Basically, I have

  • 0

I’ve been stuck trying to write this regular expression I need. Basically, I have a long string comprised of two different types of data:

  1. [a-f0-9]{32}
  2. [a-zA-Z0-9=]{x}

The thing is, x is only constant in the particular instance: if in one case, it happens to be 12, it will be 12 for that particular dataset, but next time I run the regular expression it might need to be 15, or 45 for example. I have an unpredictable number of type (1)’s between each piece of type (2). My goal is to “harvest” all the data of type (2).

For example I could have a string of the following form:

[a-f0-9]{192}
[a-zA-Z0-9=]{11}
[a-f0-9]{96}
[a-zA-Z0-9=]{11}
[af-0-9]{160}
[a-zA-Z0-9=]{11}

(All put together with no delimitations). I need it to return a string comprised of the 33 characters of the [a-zA-Z0-9=] character set. The fact that the number
of characters in each of the substrings is constant in the instance (in the case above it was 11, but it could just have easily have been 13) is vital as since it contains the smaller character set it would otherwise be impossible to know where one string begins and the other ends.

I’ve been trying to get this to work for almost a month now, and I’m close to tearing out my hair. I’m not particularly good at regular expressions…

Example data:

3c21e03a10b9415fb3e1067ea75f8205
c8dc9900a5089d31e01241c7a947ed7e
d5f8cd6bb86ebef6d7d104c84ae6e8a7
e23c99af9c9d6d0294d8b51094c39021
4bb4af7e61760735ba17c29e8f542a66
875da91e90863f1ddb7e149297fc59af
cf5de951fb65d06d2927aab7b9b54830
e2d935616a54c381c2f38db3731d5a37
SGVsbG8gbXk
6dd11d15c419ac219901f14bdd999f38
0ad94e978ad624d15189f5230e5435a9
2dc19fe95e583e7d593dd52ae7e68a6e
465ffa6074a371a8958dad3ad271181a
23310939b981b4e56f2ecee26f82ec60
fe04bef49be47603d1278cc80673b226
gbmFtZSBpcy
3c21e03a10b9415fb3e1067ea75f8205
c8dc9900a5089d31e01241c7a947ed7e
d5f8cd6bb86ebef6d7d104c84ae6e8a7
e23c99af9c9d6d0294d8b51094c39021
BvbGl2ZXIga
4bb4af7e61760735ba17c29e8f542a66
875da91e90863f1ddb7e149297fc59af
cf5de951fb65d06d2927aab7b9b54830
e2d935616a54c381c2f38db3731d5a37
G9vcmF5IQ==

I would want to extract “SGVsbG8gbXkgbmFtZSBpcyBvbGl2ZXIgaG9vcmF5IQ==”.

  • 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-13T07:18:22+00:00Added an answer on May 13, 2026 at 7:18 am

    It’s your lucky day! The problem is not solvable in general, but I believe that the following will nearly always give the right answer for typical data from real life:

    <?php
    
    $s = '
    3c21e03a10b9415fb3e1067ea75f8205
    c8dc9900a5089d31e01241c7a947ed7e
    d5f8cd6bb86ebef6d7d104c84ae6e8a7
    e23c99af9c9d6d0294d8b51094c39021
    4bb4af7e61760735ba17c29e8f542a66
    875da91e90863f1ddb7e149297fc59af
    cf5de951fb65d06d2927aab7b9b54830
    e2d935616a54c381c2f38db3731d5a37
    SGVsbG8gbXk
    6dd11d15c419ac219901f14bdd999f38
    0ad94e978ad624d15189f5230e5435a9
    2dc19fe95e583e7d593dd52ae7e68a6e
    465ffa6074a371a8958dad3ad271181a
    23310939b981b4e56f2ecee26f82ec60
    fe04bef49be47603d1278cc80673b226
    gbmFtZSBpcy
    3c21e03a10b9415fb3e1067ea75f8205
    c8dc9900a5089d31e01241c7a947ed7e
    d5f8cd6bb86ebef6d7d104c84ae6e8a7
    e23c99af9c9d6d0294d8b51094c39021
    BvbGl2ZXIga
    4bb4af7e61760735ba17c29e8f542a66
    875da91e90863f1ddb7e149297fc59af
    cf5de951fb65d06d2927aab7b9b54830
    e2d935616a54c381c2f38db3731d5a37
    G9vcmF5IQ==
    ';
    $s = preg_replace('/\r?\n/', '', $s);
    
    for ($i = 1; $i < 20; ++$i) {
        $pattern = "/^(([a-f0-9]{32})+([a-zA-Z0-9=]{{$i}})?)+$/";
        if (preg_match($pattern, $s)) {
            $pattern = "/(?:[a-f0-9]{32})+([a-zA-Z0-9=]{{$i}})/";
            $matches = array();
            preg_match_all($pattern, $s, $matches);
            print_r(join('', $matches[1]));
            break;
        }
    }
    

    Output in this case:

    SGVsbG8gbXkgbmFtZSBpcyBvbGl2ZXIgaG9vcmF5IQ==
    

    I believe that the code could be improved, but I’m sure you’re just happy to get something that works. I think this is similar to the “bazooka” method you described above, but I honestly don’t think there is a better way. Note also that it is important to start with small guesses first to minimize the chance of false matches. The order of the terms in the regex is also important to increase the likelihood of choosing correctly when more than one choice is possible (try hardest to match first, greedy, then easiest match only if that fails).

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

Sidebar

Ask A Question

Stats

  • Questions 370k
  • Answers 370k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer template<class Base> struct Concrete : Base { void abstractMethod(); void… May 14, 2026 at 6:36 pm
  • Editorial Team
    Editorial Team added an answer The first step is to index the geometry column. Something… May 14, 2026 at 6:36 pm
  • Editorial Team
    Editorial Team added an answer I would wait until the DOM has loaded before making… May 14, 2026 at 6:36 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.