简体   繁体   English

如何检查字符串是否包含(数字)

[英]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 搏击俱乐部(2008)-> true

Sick (Documentary 2008) -> false 生病(纪录片2008)->错误

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 \\" \\' \\ )" 我收到一个错误“无效的转义序列(有效的是\\ 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. 请记住, String#matches期望匹配完整的输入。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查字符串是否包含Java中的数字格式? - How to check that the string contains the number format in Java? 如何检查字符串是否包含给定字符串,该字符串不是另一个给定字符串的一部分? - How can I check whether a string contains a given string, that is not a part of another given string? 如何检查字符串是否包含关键字? - How do I check if a string contains keywords? 如何检查 Java 字符串是否至少包含一个大写字母、小写字母和数字? - How do I check if a Java String contains at least one capital letter, lowercase letter, and number? 如何检查字符串是否为浮点数? - how can I check if a string is a floating point number? 检查字符串是否包含大于数字的数字 - check if string contains number larger than a number 如何检查文件中是否包含用户输入的特定数字? (Java)的 - How can I check if a file contains a certain number that the user has input? (java) 如何检查 JSON 数组的 object 是否包含 Android Java 中具有特定名称的数字? - How can I check if object of JSON array contains number with certain name in Android Java? 如何检查String是否包含ArrayList中列出的具有Java中多个域的域名? - How can I check if String contains the domain name listed in ArrayList having multiple domains in Java? 我如何检查字符串是否包含用户给定单词的字母 - How can i check a string whether it contains letters of a given word by user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM