我试图找到一种方法来从字符串中提取单词,只要它包含该单词中的3个或更多数字/数字。这也将需要返回像正则表达式搜索包含3个或更多数字的字符串
TX-23443
或FUX3329442
等整个文本...
从我发现
\w*\d\w*
破折号之前不会返回任何字母像第一个例子?
我在网上找到的所有例子似乎都不适合我。任何帮助表示赞赏!
我试图找到一种方法来从字符串中提取单词,只要它包含该单词中的3个或更多数字/数字。这也将需要返回像正则表达式搜索包含3个或更多数字的字符串
TX-23443
或FUX3329442
等整个文本...
从我发现
\w*\d\w*
破折号之前不会返回任何字母像第一个例子?
我在网上找到的所有例子似乎都不适合我。任何帮助表示赞赏!
试试这个:
string strToCount = "Asd343DSFg534434";
int count = Regex.Matches(strToCount,"[0-9]").Count;
如果我正确理解你的问题,你想找到所有包含3+ consequtive号码就如TX-23443或FUX3329442所以你想提取TX-23443
字符串和FUX3329442
即使它包含-
之间的字符串。因此,这里是这可能会帮助你
string InpStr = "TX-23443 or FUX3329442";
MatchCollection ms = Regex.Matches(InpStr, @"[A-Za-z-]*\d{3,}");
foreach(Match m in ms)
{
Console.WriteLine(m);
}
这一个应该做的伎俩假设你的“话”解只标准拉丁单词字符:A-Z,A-Z,0-9和_。
Regex word_with_3_digits = new Regex(@"(?#!cs word_with_3_digits Rev:20161129_0600)
# Match word having at least three digits.
\b # Anchor to word boundary.
(?: # Loop to find three digits.
[A-Za-z_]* # Zero or more non-digit word chars.
\d # Match one digit at a time.
){3} # End loop to find three digits.
\w* # Match remainder of word.
\b # Anchor to word boundary.
", RegexOptions.IgnorePatternWhitespace);
即使最后还有短跑,这个人似乎也在为我工作。
[ - ] \ W [ - ] \ d {3} [ - ] \ W * [ - ] \ W
u能显示您的字符串的外观。到目前为止您尝试过的产品的确切输出是什么? –
我忘了提及它也需要返回整个文本,如 – mike11d11
我忘了提及它也需要返回整个文本,如TX-23443或FUX3329442等......从我发现的“\ w * \ d \ w *“不会像第一个例子那样在短划线之前返回任何字母? – mike11d11