【发布时间】:2021-11-24 05:11:19
【问题描述】:
我正在尝试创建两个正则表达式来捕获欧洲车牌所需的字符。
我目前正在使用两个正则表达式
- 占领国家
(^[A-Z]{1,3}[\\s])
- 占领区
-
(([^\\s*-A-Z]{1,3}[*])|([^\\s*-A-Z]{1,3}[-]))
-
以下是我拥有的车牌格式示例:
D HG-ABCDE : Country should be D, District should be HG
A S-FGHIJ : Country should be A, District should be S
D AC-KLMNO : Country should be D, District should be AC
A BR-PQRST : Country should be A, District should be BR
A RO*UVWXY : Country should be A, District should be RO
一旦我从我的字符串中获得了所需的信息,我就会使用 java 代码删除我不需要的信息,这是代码片段:
if (matcher.find()) {
country_region = matcher.group(1);
country_region = country_region.replace("*", "");
country_region = country_region.replace("-", "");
country_region = country_region.replaceAll("\\s+$", "");
}
现在我已经解释了我的主题,这就是我遇到的问题。 我的 District RegEx 没有按预期工作,它选择了错误的字母,然后导致我这边的映射错误。不幸的是,我找不到我的错误,我在这里寻求帮助!
我如何重写我的地区正则表达式以检索字母在分隔国家和地区的空格之后但在分隔符 * 或 - 之前?
非常感谢!
【问题讨论】:
标签: regex regex-group