我正在解析选举比赛文件,我需要使用仅与这些比赛相关联的部分短语来识别某些比赛。我能弄清楚如何做到这一点的唯一方法是使用REGEX,我几乎没有经验。
考虑SQL表中的以下列,我需要REGEX捕获这些列中的每一个。还有许多其他竞赛不需要被捕获,而其他竞争可能有不同的整数(例如命题):
contesttitlecleaned
ATTORNEY GENERAL
CORPORATION COMMISSIONER
Race Statistics
REGISTERED VOTERS - TOTAL
Registration & Turnout
State Rep Dst 1 (vote for 2)
STATE REP. - DIST. 14 (ELECT 2) STATE REP DIST 14
State Senator Dist. 7
US Rep Dst 1
Proposition 304
BALLOTS CAST - BLANK
BALLOTS CAST - TOTAL
这是我目前的代码:
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
string keywords1 = "\b(attorney|ballots|corporation|proposition|statistics|regist|state|US)";
if (Regex.Match(Row.contesttitlecleaned, keywords1, RegexOptions.Singleline | RegexOptions.IgnoreCase).Success)
{
Row.ctkeyword1 = Row.contesttitlecleaned;
}
}
正则表达式没有找到任何关键词