[英]Translate php regex to java
I have trouble to translate this php regex /^([-\\.\\w]+)$/
to java regex. 我很难将此php regex /^([-\\.\\w]+)$/
为Java regex。
I try ^([-\\\\.\\\\w]+)$
but don't work. 我尝试^([-\\\\.\\\\w]+)$
但不起作用。
The regex is used to validate a string used for a name of file. 正则表达式用于验证用于文件名的字符串。
in PHP is not allowed têst.ext
, but in JAVA it's. 在PHP中不允许têst.ext
,但在JAVA中是允许的。
In java, it would be: 在Java中,它将是:
str.matches("[-.\\w]+")
^
or $
with java's String#matches()
because it's implied (the whole string must match) 无需将^
或$
与Java的String#matches()
因为这是隐式的( 整个字符串必须匹配)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.