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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:42:09+00:00 2026-06-15T05:42:09+00:00

Is there a regex that would work with String.split() to break a String into

  • 0

Is there a regex that would work with String.split() to break a String into contiguous characters – ie split where the next character is different to the previous character?

Here’s the test case:

String regex = "your answer here";
String[] parts = "aaabbcddeee".split(regex);
System.out.println(Arrays.toString(parts));

Expected output:

[aaa, bb, c, dd, eee]

Although the test case has letters only as input, this is for clarity only; input characters may be any character.


Please do not provide “work-arounds” involving loops or other techniques.

The question is to find the right regex for the code as shown above – ie only using split() and no other methods calls. It is not a question about finding code that will “do the job”.

  • 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-15T05:42:10+00:00Added an answer on June 15, 2026 at 5:42 am

    It is totally possible to write the regex for splitting in one step:

    "(?<=(.))(?!\\1)"
    

    Since you want to split between every group of same characters, we just need to look for the boundary between 2 groups. I achieve this by using a positive look-behind just to grab the previous character, and use a negative look-ahead and back-reference to check that the next character is not the same character.

    As you can see, the regex is zero-width (only 2 look around assertions). No character is consumed by the regex.

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

Sidebar

Related Questions

Is there some regex that can be passed to re-seq such that it will
There is a method Regex.Replace(string source, string pattern, string replacement) The last parameter supports
I would like to make function which detects/validates that a string got at least
I would really want to have a Regex that is executable in node.js (so
What is the most efficient regex that will match these domains, without having to
I'm trying to find eveything inside a div using regexp. I'm aware that there
I am parsing some HTML source. Is there a regex script to find out
There's many regex's out there to match a URL. However, I'm trying to match
I have noticed in the PHP regex library there is a choice between ereg
Possible Duplicate: Regex to match URL Is there a regular expression to return a

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.