Reputation: 165
I am trying to find words with spaces that are surrounded by (
, )
or ,
and wrap them in quotes..
For e.g. In this expression - Development life cycle
and enterprise service bus
are to be wrapped in quotes.
Edit - Only phrases i.e. Words that contain spaces between them are to be wrapped
(AND(OR(SDLC,development life cycle),design,requirements,OR(biztalk,Websphere,TIBCO,Webmethods,ESB,enterprise service bus)))
Upvotes: 3
Views: 2949
Reputation: 67968
(?<=[(,])([^(),]* [^(),]*)(?=[),])
Try this. See DEMO.
Replace by "$1"
or "\1"
string strRegex = @"(?<=[(,])([^(),]* [^(),]*)(?=[),])";
Regex myRegex = new Regex(strRegex, RegexOptions.Multiline);
string strTargetString = @"(AND(OR(SDLC,development life cycle),design,requirements,OR(biztalk,Websphere,TIBCO,Webmethods,ESB,enterprise service bus)))" + "\n" + @" AND(OR(SDLC,""development life cycle""),OR(banking,AML,anti-money laundering,KYC,know your customer),OR(technology strategy,technical strategy,technical architecture,technology architecture,architect*)";
string strReplace = @"""$1""";
return myRegex.Replace(strTargetString, strReplace);
Upvotes: 2