SPeL returns 子字符串而不是布尔值的正则表达式
SPeL Regular expression that returns substring rather than boolean value
有没有办法将 return 源字符串的匹配子字符串作为 SPeL 表达式,而不是包含正则表达式?
例如,
<property name="emailValid"
value="#{user.email matches '^[_A-Za-z0-9-]+(.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(.[A-Za-z0-9]+)*(.[A-Za-z]{2,})$'}"/>
将 return if user.email 的布尔值匹配正则表达式
然而我正在寻找的是类似
(如果test.url="helloworld/iwantthispart"
)
<property name="theNewSubstring"
value="#{test.url imaginaryMethod '[^\/]+$'}"/>
然后 属性 thenNewSubstring
将等于 iwantthispart
我也在使用 Spring,如果框架中有任何我不知道的 gem。
不幸的是,在 spring 表达式语言中只有 str>、<、>=、<=、instanceOf、匹配和运算符之间。
您可以在 spring xml 中编写如下代码:
boolean value = parser.parseExpression("T(java.util.regex.Pattern).compile('.*').matcher('abc').matches()").getValue(Boolean.class);
或者从匹配器中提取你需要的组。
有没有办法将 return 源字符串的匹配子字符串作为 SPeL 表达式,而不是包含正则表达式?
例如,
<property name="emailValid"
value="#{user.email matches '^[_A-Za-z0-9-]+(.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(.[A-Za-z0-9]+)*(.[A-Za-z]{2,})$'}"/>
将 return if user.email 的布尔值匹配正则表达式
然而我正在寻找的是类似
(如果test.url="helloworld/iwantthispart"
)
<property name="theNewSubstring"
value="#{test.url imaginaryMethod '[^\/]+$'}"/>
然后 属性 thenNewSubstring
将等于 iwantthispart
我也在使用 Spring,如果框架中有任何我不知道的 gem。
不幸的是,在 spring 表达式语言中只有 str>、<、>=、<=、instanceOf、匹配和运算符之间。
您可以在 spring xml 中编写如下代码:
boolean value = parser.parseExpression("T(java.util.regex.Pattern).compile('.*').matcher('abc').matches()").getValue(Boolean.class);
或者从匹配器中提取你需要的组。