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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:21:28+00:00 2026-06-18T17:21:28+00:00

I never understood how to make properly regex to divide my Strings. I have

  • 0

I never understood how to make properly regex to divide my Strings.
I have this types of Strings example = "on[?a, ?b, ?c]";
Sometimes I have this, Strings example2 = "not clear[?c]";

For the first Example I would like to divide into this:

[on, a, b, c] 

or

String name = "on";
String [] vars = [a,b,c];

And for the second example I would like to divide into this type:
[not clear, c]
or

String name = "not clear";
String [] vars = [c];

Thanks alot in advance guys 😉

  • 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-18T17:21:30+00:00Added an answer on June 18, 2026 at 5:21 pm

    If you know the character set of your identifiers, you can simply do a split on all of the text that isn’t in that set. For example, if your identifiers only consist of word characters ([a-zA-Z_0-9]) you can use:

    String[] parts = "on[?a, ?b, ?c]".split("[\\W]+");
    String name = parts[0];
    String[] vars = Arrays.copyOfRange(parts, 1, parts.length);
    

    If your identifiers only have A-Z (upper and lower) you could replace \\W above with ^A-Za-z.

    I feel that this is more elegant than using a complex regular expression.

    Edit: I realize that this will have issues with your second example “not clear”. If you have no option of using something like an underscore instead of a space there, you could do one split on [? (or substring) to get the “name”, and another split on the remainder, like so:

    String s = "not clear[?a, ?b, ?c]";
    String[] parts = s.split("\\[\\?"); //need the '?' so we don't get an extra empty array element in the next split
    String name = parts[0];
    String[] vars = parts[1].split("[\\W]+");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I never understood this: in web development whe[ n|re ] does it make sense
Never thought I'd have this problem :) The following snippet of code works in
I understand what is happening in this skip_tracks method, however, I never could have
I have never understood why some people say making custom css for each browser
I have never understood what a nested transaction is good for. Committing a nested
I'm Having trouble with regex. Never fully understood it the real question is: does
I have a brute force algorithm, but never fully understood it. I have a
There is one thing I never understood about references and I hope that one
I never clearly understood what an ABI is. Please don't point me to a
I've never really understood on how to do it. I want to where where

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.