我有一个很长的文字,在文字中有很多这样的东西(你好,嗨)或(你好,嗨),我必须考虑到空间。如何在长文本中检测它们并检索 hello 和 hi 词并从文本中添加到列表中?目前我使用这个正则表达式:
string helpingWordPattern = "(?<=\\()(.*?)(?<=\\))";
Regex regexHelpingWord = new Regex(helpingWordPattern);
foreach (Match m in regexHelpingWord.Matches(lstQuestion.QuestionContent))
{
// removing "," and store helping word into a list
string str = m.ToString();
if (str.Contains(","))
{
string[] strWords = str.Split(','); // Will contain a ) with a word , e.g. ( whole) )
if(strWords.Contains(")"))
{
strWords.Replace(")", ""); // Try to remove them. ERROR here cos i can't use array with replace.
}
foreach (string words in strWords)
{
options.Add(words);
}
}
}
我谷歌并搜索正确的正则表达式,我使用的正则表达式也想删除 ) 但它没有。