Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要从文件的行中提取邮政编码。每行包含一个地址,并以不同的方式格式化。例如。“Großen Haag 5c, DE-47559 Kranenburg”或“Lange Ruthe 7b, 55294 Bodenheim”
邮政编码总是一个五位数字,有时跟在“DE-”后面。我使用Java。非常感谢!
\b\d{5}\b
如果它们是“单独”的,将匹配 5 个数字,即被单词边界包围(以确保我们不匹配较长数字序列的子字符串,尽管这些在地址文件中可能很少见)。
请记住,您需要转义 Java 字符串 ( "\\b\\d{5}\\b") 中的反斜杠。
"\\b\\d{5}\\b"
Pattern.matcher("[0-9]{5}")