你可以使用这个表达式\([a-zA-Z]+\(\d+\)\s*=\s*\d+\)
,这意味着
- 之后括号
\(\d+\)
- 之间的一个或多个degit后跟一个或多个空间的一个或多个字母
[a-zA-Z]+
\s*
- 其次然后等于
=
- 然后是一个或多个空间然后
- 接着是一个或多个degit
\d+
- 这一切括号
\([a-zA-Z]+\(\d+\)\s*=\s*\d+\)
与图案像这样之间:
String[] texts = new String[]{"(text text (text) text)",
"(F(1) = 44)",
"(text text [text] text)",
"[text text (text) text]"};
String regex = "\\([a-zA-Z]*\\(\\d+\\)\\s*=\\s*\\d+\\)";
for (String s : texts) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(s);
if (matcher.find()) {
System.out.println("There are match " + matcher.group());
} else {
System.out.println("No match occurred");
}
}
输出
No match occurred
There are match (F(1) = 44)
No match occurred
No match occurred
尝试一下https://regex101.com/ –
“有人可以为我做这个吗?”是完美的,表明你不知道你在哪里,所以不提供代码,它有助于你做了什么 – azro
使用'str.contains(“(F(1)= 44)”)''。 – saka1029