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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:13:23+00:00 2026-06-02T17:13:23+00:00

I can’t understand how to solve the following problem: I have input string aaaabaa

  • 0

I can’t understand how to solve the following problem:

I have input string “aaaabaa” and I’m trying to search for string “aa” (I’m looking for positions of characters)
Expected result is
0 1 2 5

  • aa aabaa
  • a aa abaa
  • aa aa baa
  • aaaab aa

This problem is already solved by me using another approach (non-RegEx).
But I need a RegEx I’m new to RegEx so google-search can’t help me really.
Any help appreciated! Thanks!

P.S.
I’ve tried to use (aa)* and "\b(\w+(aa))*\w+" but those expressions are wrong

  • 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-02T17:13:25+00:00Added an answer on June 2, 2026 at 5:13 pm

    You can solve this by using a lookahead

    a(?=a)
    

    will find every “a” that is followed by another “a”.

    If you want to do this more generally

    (\p{L})(?=\1)
    

    This will find every character that is followed by the same character. Every found letter is stored in a capturing group (because of the brackets around), this capturing group is then reused by the positive lookahead assertion (the (?=...)) by using \1 (in \1 there is the matches character stored)

    \p{L} is a unicode code point with the category “letter”

    Code

    String text = "aaaabaa";
    Regex reg = new Regex(@"(\p{L})(?=\1)");
    
    MatchCollection result = reg.Matches(text);
    
    foreach (Match item in result) {
        Console.WriteLine(item.Index);
    }
    

    Output

    0
    1
    2
    5

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
Can anybody tell what is the best(easy) way to sort the following string 'index'
Can we add custom language for RecognizerIntent? I have search many SO Question like
can anyone help me in trying to check whether JavaScript is enabled in client
Can somebody help me with this. There is HTML code: <h3> <label> <input type=checkbox
I am trying to understand how to use SyndicationItem to display feed which is
I want to count how many characters a certain string has in PHP, but
Can anyone give me an example of how to return the following json simply
Can you guys help me understand a concept real quick, I'm having trouble understanding
Can't figure out how to do this in a pretty way : I have

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.