gpt4 book ai didi

java - 正则表达式 - 获取两个字符串之间的文本

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

我有一个很大的文本文件,其中包含许多摘要(其中 7k)。我想把他们分开。它们具有以下属性:

开头是一个数字,后面是一个句点

123.

并且它总是以:

结束

[PubMed - indexed for MEDLINE]

如果我能从分隔的字符串中获取标题和摘要,那就更好了。如果我必须先拆分文章然后拆分文本,我没问题。

在示例中,标题是第三行:

Effects of propofol and isoflurane on haemodynamics and the inflammatory response in cardiopulmonary bypass surgery.

摘要在第8行:

Cardiopulmonary bypass (CPB) causes reperfusion injury...

我尝试对此文本使用以下代码

正则表达式:

[0-9\.]*\s*(((?![0-9\.]*|MEDLINE).)+)\s*MEDLINE

文字:

1. Br J Biomed Sci. 2015;72(3):93-101.

Effects of propofol and isoflurane on haemodynamics and the inflammatory response
in cardiopulmonary bypass surgery.

Sayed S, Idriss NK, Sayyedf HG, Ashry AA, Rafatt DM, Mohamed AO, Blann AD.

Cardiopulmonary bypass (CPB) causes reperfusion injury that when most severe is
clinically manifested as a systemic inflammatory response syndrome. The
anaesthetic propofol may have anti-inflammatory properties that may reduce such a
response. We hypothesised differing effects of propofol and isoflurane on
inflammatory markers in patients having CBR Forty patients undergoing elective
CPB were randomised to receive either propofol or isoflurane for maintenance of
anaesthesia. CRP, IL-6, IL-8, HIF-1α (ELISA), CD11 and CD18 expression (flow
cytometry), and haemoxygenase (HO-1) promoter polymorphisms (PCR/electrophoresis)
were measured before anaesthetic induction, 4 hours post-CPB, and 24 hours later.
There were no differences in the 4 hours changes in CRP, IL-6, IL-8 or CD18
between the two groups, but those in the propofol group had higher HIF-1α (P =
0.016) and lower CD11 expression (P = 0.026). After 24 hours, compared to the
isoflurane group, the propofol group had significantly lower levels of CRP (P <
0.001), IL-6 (P < 0.001) and IL-8 (P < 0.001), with higher levels CD11 (P =
0.009) and CD18 (P = 0.002) expression. After 24 hours, patients on propofol had
increased expression of shorter HO-1 GT(n) repeats than patients on isoflurane (P
= 0.001). Use of propofol in CPB is associated with a less adverse inflammatory
profile than is isofluorane, and an increased up-regulation of HO-1. This
supports the hypothesis that propofol has anti-inflammatory activity.

PMID: 26510263 [PubMed - indexed for MEDLINE]

最佳答案

Mariano 提出了两个有用的解决方案和 stribizhev :

Mariano 的解决方案:使用带有典型结尾的 split 方法

(?m)\[PubMed - indexed for MEDLINE\]$

演示:http://ideone.com/Qw5ss2

Java 4+

stribizhev 的解决方案:从文本中完全提取数据

(?m)^\s*\d+\..*\R{2}                 # Get to the title
(?<title>[^\n]*(?:\n(?!\n)[^\n]*)*) # Get title
\R{2} # Get to the authors
[^\n]*(?:\n(?!\R)[^\R]*)* # Consume authors
(?<abstract>[^\[]*(?:\[(?!PubMed[ ]-[ ]indexed[ ]for[ ]MEDLINE\])[^\[]*)*) #Grab abstract

演示:https://regex101.com/r/sG2yQ2/2

Java 8+

关于java - 正则表达式 - 获取两个字符串之间的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33951001/

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