0

I have a small, yet annoying problem with regex. The input string (C#) to parse is like the following:

( "Lorem ipsum dolor, sit amet" + "Maecenas fermentum commodo leo.", "aaa", 120 )

I want regex to match string between first " and before first comma that is after " so I want to find:

Lorem ipsum dolor, sit amet" + "Maecenas fermentum commodo leo.

So far I came up with:

\(\s*?\"(.*?)\".*?\)

but the result is:

Lorem ipsum dolor, sit amet

Any help will be appreciated!

2 Answers 2

1

Your regex doesn't even look like it's trying to match up to any comma.

Did you maybe intend to match a comma after that second quote?

\(\s*?\"(.*?)\",.*?\)

You should also be careful of inputs such as

( "Lorem ipsum dolor\", sit amet" + "Maecenas fermentum commodo leo.", "aaa", 120 )

as funky things like that are hard to deal with using only regex.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, but what if input string is: ( "Lorem ipsum dolor, sit amet" + "Maecenas fermentum commodo leo." ) And I'd love to see solution that handles input as you proposed.
0

You can try making the separating comma optional:

\(\s*\"(.+?)(\",.*|\"\s*)\)

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.