1

I have this string:

Parameter1="Something related to this" Parameter2="Another value" Parameter3='Single quotes are permitted' Parameter4="Even HTML entities are permitted"

I want to get this list:

  1. Parameter1=Something related to this
  2. Parameter2=Another value
  3. Parameter3=Single quotes are permitted
  4. Parameter4=Even HTML entities are permitted

I tried this regex. But it's not working:

(\w+)=(('|"|")).*(('|"|"))

How can I parse this string and extract key-value pairs?

3
  • (\w+)=(['"]|")(.*?)\2, see regex101.com/r/rjIBB2/1 Commented May 20, 2022 at 7:24
  • Seems that it's not getting the &quote; in C#. I tested in RegexHero. Commented May 20, 2022 at 7:27
  • There is no &quote; entity, there is only ". You have a typo in the sample string. Commented May 20, 2022 at 7:32

1 Answer 1

3

You can use

(\w+)=(['"]|")(.*?)\2

See the regex demo. Details:

  • (\w+) - Group 1: one or more word chars
  • = - an equals sign
  • (['"]|") - Group 2: ', " or "
  • (.*?) - Group 3: any zero or more chars other than an LF char as few as possible
  • \2 - Group 2 value.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.