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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:41:22+00:00 2026-06-11T21:41:22+00:00

What I have wrong? When I set variable param=MOON I need get 333#444 but

  • 0

What I have wrong? When I set variable param=”MOON” I need get 333#444 but I’m getting: 333#444:JUPITER=555. So I just need one value at a time.

final String parameters = "WORLD=111#222:MOON=333#444:JUPITER=555:SATURN=666:";
final String param = "MOON";

Pattern pattern = Pattern.compile("(.*)(" + param + ")=(.*)(:+)(.*)");
Matcher matcher = pattern.matcher(parameters);

if(matcher.matches()) {
    System.out.println("3: " + matcher.group(3)); // Value that I needed: 333#444
}

Thank you.

  • 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-11T21:41:24+00:00Added an answer on June 11, 2026 at 9:41 pm

    I’m not totally sure, but maybe what you want is extract all key=value fields? If that is the case you should split your string at the : character and process all parts by themselves. Then match those string parts with the regular expression ([^=]+)=(.*) or, better, simply split each part at the = character. In this case you won’t even need regular expressions and possibly save program execution time! It’s easy to find the MOON= ... expression by search for MOON.

    EDIT: I did the following old Java style test program (most probably can be improved):

    class Test
    {
            public static void main(String argv[])
            {
                    String parameter="WORLD=111#222:MOON=333#444:JUPITER=555:SATURN=666";
                    String[] elements=parameter.split(":");
                    for (int i=0; i < elements.length; i++) {
                            String[] parts=elements[i].split("=", 2);
                            if ((parts.length == 2) && (parts[0].equals("MOON"))) {
                                    System.out.println("MOON is "+parts[1]);
                            }
                    }
            }
    };
    

    Output:

    MOON is 333#444
    

    In many cases using a regular expression is overkill, it can often be avoided and you save execution time. If you have a very long string you might just search for MOON and from there for the next : or end-of-string and then use split, but I would maybe use a regular expression in this case. It all depends if you need the other fields as well or not.

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

Sidebar

Related Questions

I have an issue where a variable is not getting set by a select
I have the following piece of TCL code: #wrong format: set in_val 12 0
I have Android debuggable set to false, yet the condition true. What is wrong
What am I doing wrong? I have the () to set up two Groups,
Maybe i have the wrong context but... Is there a corelib site for mysql
I'm not totally sure but this looks wrong: I have a header file named
For my app I have two route set up, app.get('/', routes.index); app.get('/:name', routes.index); I
I have JAVA_HOME variable set to C:\Program Files\Java\jre6\ when I run maven package on
JS/JQuery Newb here! I have a value stored in variable, and I need to
I'm new to linq and linq to entities so I might have gone wrong

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.