如何仅替换\ n之后具有一些字符的字符

问题描述 投票:0回答:1

我使用pdfminer将pdf转换为txt。问题是pdfminer在pdf行的末尾添加了\ n,但句子并未在此结束。您会在下面的文本中看到每一行都是句子,这是不对的。我还给出了其他版本的文本,以显示新行字符在哪里。例如

quan-
tum population.

应该用一句话。因此,我用\ n替换了\ n,此问题已解决。但是其他\ n都替换了我不想要的。

Balanced Quantum Classical Evolutionary Algorithm(BQCEA)

Muhammad Shahid, Hasan Mujtaba, Muhammad Asim, Omer Beg

Abstract
With advancement in Quantum computing, classical algorithms are adapted and integrated
with Quantum properties such as qubit representation and entanglement. Although these
properties perform better however pre-mature convergence is the main issue in Quantum
Evolutionary Algorithms(QEA) because QEA uses only the best individual to update quan-
tum population. In this paper, we introduced a new way to update the quantum population
of QEA to avoid premature convergence

'Balanced Quantum Classical Evolutionary Algorithm(BQCEA)\n\nMuhammad Shahid, Hasan Mujtaba, 
Muhammad Asim, Omer Beg\n\nAbstract\nWith advancement in Quantum computing, classical 
algorithms are adapted and integrated\nwith Quantum properties such as qubit representation 
and entanglement', ' Although these\nproperties perform better however pre-mature 
convergence is the main issue in Quantum\nEvolutionary Algorithms(QEA) because QEA uses only 
the best individual to update quan-\ntum population', ' In this paper, we introduced a new 
way to update the quantum population\nof QEA to avoid premature convergence',

我已经尝试过此代码。

lines =tokenize.sent_tokenize(txt_str)
for l in lines:
    s = l.replace('\n', '')
    print(s)

这导致此。

Balanced Quantum Classical Evolutionary Algorithm(BQCEA)Muhammad Shahid, Hasan Mujtaba, Muhammad Asim, Omer BegAbstractWith advancement in Quantum computing, classical algorithms are adapted and integratedwith Quantum properties such as qubit representation and entanglement.
Although theseproperties perform better however pre-mature convergence is the main issue in QuantumEvolutionary Algorithms(QEA) because QEA uses only the best individual to update quan-tum population.
In this paper, we introduced a new way to update the quantum populationof QEA to avoid premature convergence.

但是这不是想要的文本。我想要此版本的文本。

Balanced Quantum Classical Evolutionary Algorithm(BQCEA)

Muhammad Shahid, Hasan Mujtaba, Muhammad Asim, Omer Beg

Abstract
With advancement in Quantum computing, classical algorithms are adapted and integrated with Quantum properties such as qubit representation and entanglement. Although these properties perform better however pre-mature convergence is the main issue in Quantum Evolutionary Algorithms(QEA) because QEA uses only the best individual to update quan-tum population. In this paper, we introduced a new way to update the quantum population of QEA to avoid premature convergence

我不希望空行消失。希望您能理解。

python regex string newline
1个回答
0
投票

您可以如下尝试-\n的特定用例:

re.sub(r"-\n","",l)

输出:

'Balanced Quantum Classical Evolutionary Algorithm(BQCEA)\n\nMuhammad Shahid, Hasan Mujtaba, \nMuhammad Asim, Omer Beg\n\nAbstract\nWith advancement in Quantum computing, classical \nalgorithms are adapted and integrated\nwith Quantum properties such as qubit representation \nand entanglement', ' Although these\nproperties perform better however pre-mature \nconvergence is the main issue in Quantum\nEvolutionary Algorithms(QEA) because QEA uses only \nthe best individual to update quantum population', ' In this paper, we introduced a new \nway to update the quantum population\nof QEA to avoid premature convergence',
© www.soinside.com 2019 - 2024. All rights reserved.