繁体   English   中英

房屋信件的正则表达式模式

[英]Regex pattern for house letter

我正在寻找能找到房子字母的正则表达式模式。

Eks(寻找字母d)。

1. Streetname 3d, 7000 Town Country. 
2. Streetname 3 d, 7000 Town Country. 
3. Streetname 13d, 7000 Town Country. 
4. Streetname 13 d, 7000 Town Country. 

我在写C#。

一些组合:

const string address = "Streetname 3d, 7000 Town Country";
string streetPart = address.Split(',')[0];
char letter = streetPart[streetPart.Length - 1];
bool isLetter = char.IsLetter(letter);
Debug.WriteLine("{0}, isLetter: {1}", letter, isLetter);

可能会工作...

输出: d, isLetter: true

我认为这种模式适用于您的4种情况。 我不测试代码,而是尝试并告诉我。

string sPattern = "[a-zA-Z 0-9]*([a-zA-Z]),.*";
int i = 0;
foreach (string s in address)
{
     Match m = Regex.Match(s, sPattern);
     if (m.Success){
         houseLetter[i] = m.ToString(); 
     } else {
         houseLetter[i] = "Not Found";
     }
     i++;
}

如果您认为有一个正则表达式可以普遍解决此问题,请停止思考。 通过您的计划,我父母的街道地址将是

Ioakim 3rd 4242, 7000 Town Country    // "Ioakim 3rd" is the street name

如您所见,您肯定会有一定百分比的错误结果。 您的四个示例是唯一需要保证正确结果的情况吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM