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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:09:05+00:00 2026-06-05T07:09:05+00:00

I have a string I need to get array (2 – dim) of key->value

  • 0

I have a string I need to get array (2 – dim) of key->value pairs.

A “match” is when there is a -> between 2 words, mo spaces before and after ->

For example input string:

skip_me key1->value1 key2->value2 skip_me_2 key3->value3 skip_me_3 skip_me -> also

The result should be array:
key1,value1
key2,value2
key3,value3

This is my code:

Pattern p = Pattern.compile( "\\s*([^(->)]+)->([^(->)]+)\\s*" );
Matcher m = p.matcher("skip_me key1->value1 key2->value2 skip_me_2 key3->value3 skip_me_3");
while( m.find() ) {
  System.out.println( "Key:" + m.group(1) + "Value:" + m.group(2) );
}

My regex is wrong.
Please assist.

  • 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-05T07:09:06+00:00Added an answer on June 5, 2026 at 7:09 am

    Matches word characters (letters, digits, and underscore _)… as many as it can

    Pattern.compile( "(\w+)->(\w+)" );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string array and i need to populate its value to a
I have a string array, and I need to get a range out of
I have an array of players (string[]) and now I need to get an
I have this string (Java 1.5): :alpha;beta:gamma;delta I need to get an array: {:alpha,
I have this string: 123-456-7 I need to get this string: 1234567 How I
I have a string 2010-08-02 12:13:06.0 and need to get something like Fri Aug
I have the string SUM([A2:A10],[B2:B10],[C2:C10],[D2:D10]) and I need to get the elements [A2:A10],[B2:B10],[C2:C10],[D2:D10] in
For eg., i have alphanumeric string 'ABCDEF 0 0.450' and i need to get
For example, I have a string: test1@test2 . I need to get the test2
I need to get the last character of a string. Say I have testers

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.