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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:57:16+00:00 2026-05-14T20:57:16+00:00

How can I parse a strings like : name1=val1 name2=val2 name3=val3 I cannot use

  • 0

How can I parse a strings like :

name1="val1"    name2="val2"    name3="val3"

I cannot use split(\s+) as it can be name = "val 1".
I am doing java but any laguage is okay.

  • 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-05-14T20:57:16+00:00Added an answer on May 14, 2026 at 8:57 pm

    Here it is in Java, with a slight variation on the regex, with capturing group to put the name/value pairs into a Map<String,String>.

    This usage of Matcher.find() in a while loop is typical.

        import java.util.*;
        import java.util.regex.*;
        //...
    
        String pattern = "(\\w+)\\s*=\\s*\"([^\"]*+)\"";
    
        String text = "name1 = \"val 1\"    name2=\"val2\"    name3=\"val3\"";
        System.out.println(text);
        // name1 = "val 1"    name2="val2"    name3="val3"
    
        Matcher m = Pattern.compile(pattern).matcher(text);
        Map<String,String> map = new HashMap<String,String>();
        while (m.find()) {
            map.put(m.group(1), m.group(2));
        }
        System.out.println(map);
        // {name3=val3, name1=val 1, name2=val2}
    

    API links

    • java.util.Map<K,V>
    • java.util.regex.Pattern
    • java.util.regex.Matcher

    regular-expressions.info links

    • Character classes
    • Grouping and backreferences
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to contruct a parser in scala which can parse simple SQL-like strings.
How can I parse a string like 01-Jan-1995 to a Python datetime object?
I need a PHP Regex that can parse .strings files. In particular, it needs
I need to parse a XML String so I can use some of the
I'm trying to use dynatree, and it can be initialized like this: var treeData
I'm trying to use regexp to parse a string like similar to this: <tag>Text
Can/Should I use a LIKE criteria as part of an INNER JOIN when building
I have a cell array 3x1 like this: name1 = text1 name2 = text2
I have to parse a String that can assume hex values or other non-hex
Can Html Agility Pack be used to parse an html string fragment? Such As:

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.