I would like to extract all double quoted phrase inside an input phrase and keep non matching elements as words
let’s say i have “sales people” IT i want the output to be:
sales people
IT
same thing for input=”SO \”sales manager\” marketing \”management\””
the output is:
SO
sales manager
marketing
management
if input =”SO \”sales manager\” marketing management\” insurance”
the output is:
SO
sales manager
marketing
management
insurance
I have found the regex :but i don’t know how to extract:
string InputText="SO \"sales manager\" marketing \"management\"" ;
string pattern0 = "^\"(.*?)\"$";
string pattern = "^(.*?)\"(.*?)\"(.*?)$";
Regex regex = new Regex(pattern);
string[] temOperands;
bool isMatch = regex.IsMatch(InputText);
if (isMatch)
{
//here goes the extraction
}
I think you need something like
"(?<word>[^"]+)"|(?<word>\w+). This will match both text in double quotes and single words:For the test string this will return: