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

后端 未结 3 1883
旧时难觅i
旧时难觅i 2020-12-06 11:41

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)$  

I g

3条回答
  •  北海茫月
    2020-12-06 12:28

    This should work ^(?:(?:([01]?\\d|2[0-3]):)?([0-5]?\\d):)?([0-5]?\\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).

提交回复
热议问题