[英]Java - Spring injected RegEx - Illegal Character - Ampersand
I'm using Spring to inject a RegEx pattern from a properties file but I'm running into an error involving the Ampersand. 我正在使用Spring从属性文件中注入RegEx模式,但是遇到与&符有关的错误。
Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal
character range near index 34 [ A-Za-z0-9¦#_/<>[]():^¬+=%$£!`@'-&,.";*?\€]
My expression is: 我的表达是:
[ A-Za-z0-9\¦#_/<>[\]():^¬+=%$£!`@'\-\u0026,.";*?\\\u20AC]
It works on RegExPal 它适用于RegExPal
I've tried escaping the character and using UniCode but I still get the same error. 我尝试转义字符并使用UniCode,但仍然遇到相同的错误。
Does anyone know if there's something in Java / Spring that's causing this to happen? 有谁知道Java / Spring中是否有某些原因导致这种情况发生?
Double escape the hyphen or keep it at first or last position in your character class: 连字符连字符两次转义,或将其保持在字符类的第一个或最后一个位置:
[- A-Za-z0-9¦#_/<>[\\]():^¬+=%$£!`@'\\u0026,.";*?\\\\\\u20AC]
You can clearly see from the error that it has removed the escaping here: 您可以从错误中清楚地看到它已删除此处的转义:
character range near index 34 [ A-Za-z0-9¦#_/<>[]():^¬+=%$£!`@'-&,.";*?\€]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.