Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

java - Invalid escape sequence (valid ones are  f " ' )

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 get the following error

"Invalid escape sequence (valid ones are   
 f 
 " '  )"  

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.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...