?
Solved

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

Posted on 2008-11-11
2
Medium Priority
?
982 Views
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!

0
Comment
Question by:fischermx
2 Comments
 
LVL 1

Accepted Solution

by:
3asfourieh earned 2000 total points
ID: 22933175
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     "
0
 
LVL 1

Author Closing Comment

by:fischermx
ID: 31515638
Great! Thank you!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
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…
Suggested Courses

621 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