我有以下问题:
我有四个文本:
1)“345-0属于合同”
2)“345-0属于合同555-55.00”
3)“未找到帐户”
4)“345-0自2014年10月22日起属于合同”
结果: 1)应该找到文本
2)应忽略文字
3)应忽略文字
4)应该找到文字
如何安装找到345-0(999-9)且同一段落中没有格式555-55.00(999-99.99)的模式?
答案 0 :(得分:0)
您可能想要使用正则表达式。
可能的模式可以是@"^[0-9-]+[^0-9-]*$"
上面会找到以数字和破折号后跟非数字字符组合开头的任何字符串。
Regex.IsMatch("345-0 belongs to a contract", @"^[0-9-]+[^0-9-]*$"); // True
Regex.IsMatch("345-0 belongs to the contract 555-55.00", @"^[0-9-]+[^0-9-]*$"); // False
Regex.IsMatch("The account not found", @"^[0-9-]+[^0-9-]*$"); // False
答案 1 :(得分:0)
这可能有效(与上一个问题几乎相同)
# @"(?s)^(?=(?:(?!\d+-\d{2}\.\d{3}).)+$).*\d+-\d.*$"
(?s) # Dot-All
^ # BOS
(?= # Not this form anywhere in the string
(?:
(?! \d+ - \d{2} \. \d{3} )
.
)+
$
)
.* \d+ - \d .* # Form needed
$ # EOS