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

  • Home
  • SEARCH
  • 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 8308119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:42:12+00:00 2026-06-08T18:42:12+00:00

Better explained with examples: HHH HHHH HHHBBHHH HHHBH BB HHBH I need to come

  • 0

Better explained with examples:

  1. HHH
  2. HHHH
  3. HHHBBHHH
  4. HHHBH
  5. BB
  6. HHBH

I need to come up with a regexp that matches only 3 H’s or a multiple of 3 H’s (so 6, 9, 12, … H’s are ok as well) and 5 H’s are not ok. And if possible I don’t want to use Perl regexps.

So for the input above the regexp would match (1), (3) and (6) only.
I’m just starting with regular expressions here so I don’t exactly know how I’m supposed to approach this.

edit
Just to clear something up:, an H can only be in one group of 3 H’s. The group of 3 H’s might be HHH or HHBH.
That’s why in example 2 above it is not a match because the last H is not in a group of 3 H’s. And you can’t take the last 3 H’s in a group because the middle 2 H’s have already been inside a group before.

  • 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-08T18:42:14+00:00Added an answer on June 8, 2026 at 6:42 pm

    You can use the following regular expression:

    ^([^H]*H[^H]*H[^H]*H[^H]*)+$
    

    It matches any string which contains in total 3 H or any multiple of 3. In between there might be any other character.

    Explanation:

    ^              begin of string
    (              start of group
      [^H]*H       any string of characters (or none) not including 'H' plus a single 'H'
      [^H]*H       any string of characters (or none) not including 'H' plus a single 'H'
      [^H]*H       any string of characters (or none) not including 'H' plus a single 'H'
      [^H]*        any string of characters (or none) which is not 'H'
    )+             containing the group once or twice or ...
    $              end of string
    

    By repeating the subpattern [^H]*H three times we make sure that there are indeed 3 H included, [^H]* allows any separating characters.

    Note: use either egrep or run grep with additional argument -E.

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

Sidebar

Related Questions

Okay, my issue is better explained visually: I need to make those 5 images
This is probably a basic question, better explained through code: public void checkStatus {
This issue is better demonstrated than explained, so I've set up a git repo
Alex explained what I'm looking for much better than I have: You want an
A mockup is below that probably explains better than words. Essentially, I want a
This is a design question better explained with a Stack Overflow analogy: Users can
I need to findout a better and quick way to query MySQL table to
How can I get a regular expression that matches any string that has two
I think this will be better explained with an example I have the following
I have this situation that I need to let users define decisions based on

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.