Reputation: 2203
I want to extract the data inside the quotes using regex
My Text is : boundary="s323sd2342423---"
Now i need to extract the value inside the double quotes without using substring.
I tried the following but didnt help.
String pattern = @"boundary=""(?<value>[^""]*";
Match m = Regex.Match(rawMessage, pattern);
while (m.Success)
{
boundaryString = m.Groups["value"].Value;
m = m.NextMatch();
}
Upvotes: 1
Views: 1512
Reputation: 11233
As per you details:
I want to extract the data inside the quotes using regex
Why not you just use this pattern:
"(?<value>[^"]+)"
Upvotes: 0
Reputation: 3176
With the following Regex you'll get what you want without any grouping
(?<=boundary=")[^"]+(?=")
Code to get the the quoted text:
string txt = "boundary=\"s323sd2342423---\"";
string quotedTxt = Regex.Match(txt, @"(?<=boundary="")[^""]+(?="")").Value;
Upvotes: 1
Reputation: 35353
You can use this pattern and it will work.
String pattern = @"boundary=\""(?<value>.+?)\""";
Upvotes: 1
Reputation: 23626
You need to close opening bracket of a group
String pattern = @"boundary=""(?<value>[^""]*)";
now if you go with
Console.WriteLine(m.Groups["value"].Value);
will print:
s323sd2342423---
Upvotes: 2