Regex pattern to match a word, or group of words surrounded by double quotes in C#

Posted on 2008-11-11
Last Modified: 2012-05-05
So, I have this string:

string str = "asdf \"xxxx\" 'asdf' \"yyyy uuuu\" ";

And I have this pattern:
string regPattern = @"(\x22(?<word>\w+)\x22)"

This correctly matches "xxxx", but it does not match "yyyy uuuu"
So, I changed it for:
string regPattern = @"(\x22(?<word>\w+|\s+)\x22)"

And still it does not match!

Question by:fischermx
    LVL 1

    Accepted Solution

    Try :
    string regPattern = @"(\x22(?<word>[\w|\s]+)\x22)"

    Your "string regPattern = @"(\x22(?<word>\w+|\s+)\x22)"" will try to match "aaaaaaaaaaaa" or "           " and not "aaaaaa        " or "          aaaaaaaaa" or "aaaaa      aaaaa" or "     aaaaa     "
    LVL 1

    Author Closing Comment

    Great! Thank you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now