简体   繁体   中英

How can I check if a string contains (number)

I need to test if a string contains brackets with a number in the middle

Fight Club (2008) -> true

Sick (Documentary 2008) -> false

I have this but i cant test it because I can;t compile. I get an error "Invalid escape sequence (valid ones are \\b \\t \\n \\f \\r \\" \\' \\ )"

if(title.matches("\\((\d)\\)")){

}

You can use:

if(title.matches(".*?\\(\\d+\\).*")){

}

Remember that String#matches expects to match complete input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM