C#正则表达式问题 [英] C# regex question
本文介绍了C#正则表达式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在寻找一个正则表达式,以将反向地址从文本文件中拉出.
示例字符串:
"123这是一个示例字符串123234456567,并且该字符串不断前进123234456567,仍然不断前进789232111"
因此,从此我将需要2或3个单词+数字形式的任何内容.
正确的匹配项是:
匹配1:样本字符串123
匹配2:字符串继续前进123
比赛3:仍然进行789
我相信我可以将其用作正则表达式:
"^([a-zA-z] + | [a-zA-z] +/s + [a-zA-z] +)+/s + [0-9] $"
但是,仍然没有得到结果.有任何想法吗?
预先感谢,
Suraci.
解决方案
"
但是,仍然没有得到结果.有任何想法吗?
预先感谢,
苏拉奇.
我使用了此 [
So, from this I would need anything in the format 2 or 3 Words + Number.
Correct matches would be:
Match 1: sample string 123
Match 2: string keeps going 123
Match 3: and still going 789
I believe I am close by using this as my regular expression:
"^([a-zA-z]+|[a-zA-z]+/s+[a-zA-z]+)+/s+[0-9]$"
However, still not getting results. Any ideas?
Thanks in advance,
Suraci.解决方案"
However, still not getting results. Any ideas?
Thanks in advance,
Suraci.
I used this[^] to build the expression, so you might want to tweak it a bit depending on the specific RegEx implementation (it works on the site I mentioned :) ):
(\s[a-zA-Z]+){3}\s[0-9]+
Or if {3} dosn''t work:
(\s[a-zA-Z]+\s[a-zA-Z]+\s[a-zA-Z]+)\s[0-9]+
这篇关于C#正则表达式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文