无效的转义序列(有效转义序列为\b \t \\\<br/> \f \ r \&quot; \'\) [英] Invalid escape sequence (valid ones are \b \t \n \f \r \&quot; \&#39; \ )

查看:1252
本文介绍了无效的转义序列(有效转义序列为\b \t \\\<br/> \f \ r \&quot; \'\)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在java中使用正则表达式时遇到问题。

I have a problem with a regex in java.

当我尝试使用这个正则表达式时:

When I try to use this regex:

 ^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$  

我收到以下错误

"Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \ )"  

我不知道如何处理这个错误。
我已经尝试加倍反斜杠,但它没有用。
我希望有人能帮助我。

I don't know how to handle that error. I already tried to double the backslashes, but it didn't work. I hope someone can help me with this.

谢谢

推荐答案

这应该工作 ^(?:(?:( [01]?\\d | 2 [0-3]):))([0-5]?\\\ \\ d):)?([0-5]?\\d)$

原因是列出的符号在错误消息具有特殊含义,但 \d 不是使用 \ 定义的特殊符号之一,这意味着你必须逃避它(通过添加额外的 \ 在符号前面。)

The reason is that the listed symbols in the error message have special meaning, but \d is not one of those defined special symbols for using \, this means you have to escape it (by adding an extra \ in front of the symbol).

这篇关于无效的转义序列(有效转义序列为\b \t \\\<br/> \f \ r \&quot; \'\)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆