gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 02:52:14 25 4
gpt4 key购买 nike

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

这里是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com