我使用这个Regex公式从使用SSIS和Script组件的地址列表中提取Civic号。
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
//Replace each \ with \\ so that C# doesn't treat \ as escape character
//Pattern: Start of string, any integers, 0 or 1 letter, end of word
string sPattern = "^[0-9]+([A-Za-z]\\b)?";
string sString = Row.ADDRESS ?? ""; //Coalesce to empty string if NULL
//Find any matches of the pattern in the string
Match match = Regex.Match(sString, sPattern, RegexOptions.IgnoreCase);
//If a match is found
if (match.Success)
//Return the first match into the new
//HouseNumber field
Row.CivicNumber = match.Groups[0].Value;
else
//If not found, leave the HouseNumber blank
Row.CivicNumber = "";
}
}在适合以下地址的工作中:
栏中返回我
我确实有一些这样的格式:
栏中返回我
如何修改Regex公式以返回所需的结果?
发布于 2021-03-23 06:48:18
试试这个:
string sPattern = "^[0-9]+[A-Za-z]?\\b(/[0-9]+)?";发布于 2021-03-23 05:43:39
从一个数字开始到一个空格怎么样?例如:
\d\S+

如果地址/行必须以数字开头,那么您可以使用上面所述的锚点:
^\d\S+发布于 2021-03-23 05:55:19
没有足够的声誉来评论
那么,从你的两个例子中,我可以假设第一个空格之前的子字符串是你的公民编号吗?如果是,则可以将单词拆分为空格字符,并从字符串数组中获取第一个子字符串。
String address = "49b/15 Main Street";
String[] addressArr = address.split("\\s+");
System.out.println(addressArr[0]);https://stackoverflow.com/questions/66756668
复制相似问题