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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:25:20+00:00 2026-06-04T13:25:20+00:00

i have a problem to build following regex: [1,2,3,4] i found a work-around, but

  • 0

i have a problem to build following regex:
[1,2,3,4]

i found a work-around, but i think its ugly

String stringIds = "[1,2,3,4]";
stringIds = stringIds.replaceAll("\\[", ""); 
stringIds = stringIds.replaceAll("\\]", "");
String[] ids = stringIds.split("\\,");

Can someone help me please to build one regex, which i can use in the split function
Thanks for help

edit:
i want to get from this string “[1,2,3,4]” to an array with 4 entries. the entries are the 4 numbers in the string, so i need to eliminate “[“,”]” and “,”. the “,” isn’t the problem.
the first and last number contains [ or ]. so i needed the fix with replaceAll. But i think if i use in split a regex for “,”, i also can pass a regex which eliminates “[” “]” too. But i cant figure out, who this regex should look like.

  • 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-04T13:25:21+00:00Added an answer on June 4, 2026 at 1:25 pm

    This is almost what you’re looking for:

        String q = "[1,2,3,4]";
        String[] x = q.split("\\[|\\]|,");
    

    The problem is that it produces an extra element at the beginning of the array due to the leading open bracket. You may not be able to do what you want with a single regex sans shenanigans. If you know the string always begins with an open bracket, you can remove it first.

    The regex itself means “(split on) any open bracket, OR any closed bracket, OR any comma.”

    Punctuation characters frequently have additional meanings in regular expressions. The double leading backslashes… ugh, the first backslash tells the Java String parser that the next backslash is not a special character (example: \n is a newline…) so \\ means “I want an honest to God backslash”. The next backslash tells the regexp engine that the next character ([ for example) is not a special regexp character. That makes me lol.

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

Sidebar

Related Questions

I am having the following problem: a) I have a UNIX build environment set
I have a hash with values that build into following structure: string type1_name ->
I've build a set of mod_rewrite rules but I have a problem. For example,
I have following problem: I have built a tabbar application with 4 tabs. I
I have problem developing with live555. I already build the lib-files and example projects
I have a problem with a report that is build using report builder 2.0,
I have a problem, I would like to build logging system which will be
I have a problem. I wrote example code and I want to build it
I have a small problem with UINavigationController animation between two view. My application build
I have a build problem with maven. I wrote a custom checkstyle check for

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.