java - 正则表达式匹配括号内的数值

标签 java regex

我正在尝试创建一个正则表达式来匹配括号内的每个数值。

这里是 regex101 的链接我一直用它来进行测试。

例如使用字符串:

At present there are no approved therapies to directly target NRAS activating mutations. However, N-Ras activation may predict sensitivity to inhibitors of the Raf/MEK/ERK, PI3K/Akt, and other downstream pathways (23274911, 22392911, 21993244). The MEK inhibitors trametinib and cobimetinib (in combination with vemurafenib) have been FDA-approved for BRAF V600E- and V600K-mutant melanoma, and are currently being studied in clinical trials in solid tumors and hematologic malignancies (22663011, 25265494). Several preclinical studies have suggested that combinations of MEK inhibitors with inhibitors of other downstream molecules, such as PI3K, eIF4A, and Plk1, result in synergistic growth inhibition in NRAS-mutant melanoma in vitro and in vivo (19492075).

我想匹配以粗体显示的每个值。我目前正在使用以下内容

Pattern citationPattern = Pattern.compile("(.?\()(\\d+)");
        Matcher match = citationPattern.matcher(treatmentApproach);

并且能够匹配括号内的每个第一个值。对于括号内有多个值的情况,我该如何扩展它?例如(22663011, 25265494)。感谢您的帮助!

最佳答案

我只是从文字 () 之间提取匹配。比如,

Pattern citationPattern = Pattern.compile("\\((.*?)\\)");
Matcher match = citationPattern.matcher(treatmentApproach);
while (match.find()) {
    System.out.println(match.group());
}

关于java - 正则表达式匹配括号内的数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43639011/

相关文章:

C# 正则表达式不起作用

java - 在每第 N 个字符出现时拆分字符串

php - 需要可变宽度负向后查找替换

java - 常用元数据Hashmap

java - 去除高亮匹配字符串内容

python - NLTK 正则表达式标记器 : Regex to retain just characters in Random text

Python Regex 在字符串上停止

java - 如何在 Java 中使用 SoundCloud API(Android 应用程序)

java - 现在必须显式声明注释处理器

java - Java中有弱/软双向映射吗?