M
Mark Rae
Hi,
Supposing I had a string made up of a person's name followed by their
profession in parentheses e.g.
string strText = "Tiger Woods (golfer)";
and I wanted to extract the portion of the string between the parentheses
i.e. "golfer"
Would a regular expression be the most efficient way of doing this...?
I'm trying to do something like this:
string strProfession = String.Empty;
Regex objRegEx = new Regex("(((.|\n)*?))", RegexOptions.IgnoreCase);
foreach (Match objMatch in objRegEx.Matches(strText)
{
strProfession = objMatch.ToString();
}
but that is returning an empty string, no doubt because I haven't defined
the regular expression correctly.
Also, is it even necessary to have a foreach loop here, as in this
particular scenario there can only ever be one match...?
Any assistance gratefully received.
Mark
Supposing I had a string made up of a person's name followed by their
profession in parentheses e.g.
string strText = "Tiger Woods (golfer)";
and I wanted to extract the portion of the string between the parentheses
i.e. "golfer"
Would a regular expression be the most efficient way of doing this...?
I'm trying to do something like this:
string strProfession = String.Empty;
Regex objRegEx = new Regex("(((.|\n)*?))", RegexOptions.IgnoreCase);
foreach (Match objMatch in objRegEx.Matches(strText)
{
strProfession = objMatch.ToString();
}
but that is returning an empty string, no doubt because I haven't defined
the regular expression correctly.
Also, is it even necessary to have a foreach loop here, as in this
particular scenario there can only ever be one match...?
Any assistance gratefully received.
Mark