我看到很多关于问题的问题,replaceAll
但它对我不起作用。我想用模式本身替换特定模式的出现(这样稍后我将能够运行 sql 并根据正则表达式值找到类似的记录),方法是:
https://internal-gateway.com/users/4e8a4741-dd89-4cdd-a7c3-3b2f7044e142
它应该返回
https://internal-gateway.com/users/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89AB][0-9a-f]{3}-[0-9a-f]{12}
我的代码:
private final static String UUID_PATTERN = "[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89AB][0-9a-f]{3}-[0-9a-f]{12}";
private final static String SIM_NUMBER_PATTERN = "894803[0-9]{13}";
private final static String MSISDN_SHORT_PATTERN = "[0-9]{9}";
private final static String MSISDN_LONG_PATTERN = "[0-9]{11}";
private Optional<WebApp> checkRegexes(String url, Long id) {
String urlToLookFor = url.replaceAll(UUID_PATTERN,UUID_PATTERN);
urlToLookFor=urlToLookFor.replaceAll(SIM_NUMBER_PATTERN,SIM_NUMBER_PATTERN);
urlToLookFor=urlToLookFor.replaceAll(MSISDN_LONG_PATTERN,MSISDN_LONG_PATTERN);
urlToLookFor=urlToLookFor.replaceAll(MSISDN_SHORT_PATTERN,MSISDN_SHORT_PATTERN);
return waRepository.getWebAppByRegex(urlToLookFor,id);
}
但是在给定的示例中,值replaceall 没有替换任何内容,任何人都可以提示我我的错误是什么?
慕运维8079593
相关分类