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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:05:51+00:00 2026-06-01T05:05:51+00:00

I have string like {param1=foo}{param2=bar}hello world! I need to extract array of tuples (paramName,

  • 0

I have string like {param1=foo}{param2=bar}hello world!
I need to extract array of tuples (paramName, value) from this string and get something like [(param1, foo), (param2, bar)]

Is it possible in Scala to extract this tuples by only one regex? Because I managed to do this only in way like

val str = "{param1=foo}{param2=bar}hello world!"
val param = """(?<=\{)(.+?)(?=\})""".r // extract everything between { and }
val keyValue = """(.+)=(.+)""".r // for extracting key and value
val parameters = for (keyValue(key,value) <- param.findAllIn(str).toArray) 
                     yield (key,value)

And it doesn’t look sweet.

Also I tried to use

val param = """(?<=\{)(.+?)=(.+?)(?=\})""".r

But it return param=value as one string

  • 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-01T05:05:51+00:00Added an answer on June 1, 2026 at 5:05 am

    Here’s an expression that will find things like {A=B} where A and B do not contain {, }, or =.

    scala> val Re = """\{([^{}=]+)=([^{}=]+)\}""".r
    
    scala> val Re(a,b) = "{param1=foo}"
    a: String = param1
    b: String = foo
    

    And if you want to find all matches in a string:

    scala> val s = "{param1=foo}{param2=bar}hello world!"
    
    scala> Re.findAllIn(s).matchData.map(_.subgroups).toList
    res9: List[List[String]] = List(List(param1, foo), List(param2, bar))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say, I have an XML String like this, <METHOD>foo</METHOD> <PARAM1>abc</PARAM1> <PARAM2>def</PARAM2> ... <PARAM99>ghi</PARAM99> <PARAM100>jkl</PARAM100>
I have a string expression like param1=123,param2=bbb I would like to get a list
Say, we have a query string that looks like this: param1:'test1' && param2:'test2' I
I have a bit of StructureMap config like so: x.ForConcreteType<OrderProcessor>().Configure .Ctor<string>(param1).EqualToAppSetting(setting1) .Ctor<string>(param2).EqualToAppSetting(setting2) .Ctor<string>(param3).EqualToAppSetting(setting3); This
I have a string like this that I need to parse into a 2D
When I have a method like this: public static void foo(String param) throws IOException
I have to check hashrefs like this one { foo => 65, bar =>
I have a query that is basically like this: SELECT foo FROM bar where
I have a string <ul><li e=100 n=50>Foo</li><li e=200 n=150>Bar</li></ul> and on client side I
When I am communicating with my backend I often have URL like this: http://myserver.com/api/endpoint?param1={PARAM1}&param2={PARAM2}

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.