我需要一个模式匹配字符串,将速度 ex(15.0) 提取到第二组模式匹配中,并将字符串的其余部分从以下字符串中提取到第一组中:
- 阿纳纳塔普尔,ATP (15.0)
- 库努尔 KNL (25.0)
- 海得拉巴,HYD(特伦甘纳邦)(100.0)
- 维杰亚瓦达,BZA,南部 (10.0)
- Goa Smith(STL 航站楼)(15.0)
- 加拿大、新泽西州、帕沃尼亚 (SA) (15.0)
- 密苏里州网络城市混合中心 (15.0)
- 堆叠高地,密歇根州(南澳州)(15.0)
有人可以帮我解决同样的问题吗?
最佳答案
您可以使用此正则表达式进行匹配:
^([^)]+\))\s+\(([^)]+)\)
并使用组 #1 和组 #2。
RegEx Demo
Java 正则表达式:
Patter p = Pattern.compile( "^([^)]+\\))\\s+\\(([^)]+)\\)" );
说明:
^ - start of the string
([^)]+\)) - 1st Capturing group ([^)]+\)). [^)]+\) matches anything but ) followed by a )
\s+\( - Match 1 or more white-spaces followed by (
([^)]+) - 2nd Capturing group ([^)]+). [^)]+\) matches anything but )
\) - Match lliteral )
关于java - 需要 Java 中多个大括号的模式匹配帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27729920/