Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python正则表达式清理随机放置的新行_Python_Regex_Python 2.7 - Fatal编程技术网

Python正则表达式清理随机放置的新行

Python正则表达式清理随机放置的新行,python,regex,python-2.7,Python,Regex,Python 2.7,我得到了下面的文本,希望对新行进行一些正则表达式清理 Quality risk management. A systematic process for the assessment, control, communication and review of risks to quality across the lifecycle. (ICH Q9) Simulated agents. A material that closely approximates the physical and

我得到了下面的文本,希望对新行进行一些正则表达式清理

Quality risk management. A systematic process for the assessment, control,
communication and review of risks to quality across the lifecycle. (ICH Q9)

Simulated agents. A material that closely approximates the physical and, where
practical, the chemical characteristics, e.g. viscosity, particle size, pH etc., of the product
under validation.

State of control. A condition in which the set of controls consistently provides assurance
of acceptable process performance and product quality.

Traditional approach. A product development approach where set points and operating
ranges for process parameters are defined to ensure reproducibility.

Worst Case. A condition or set of conditions encompassing upper and lower processing
limits and circumstances, within standard operating procedures, which pose the greatest
chance of product or process failure when compared to ideal conditions. Such conditions
do not necessarily induce product or process failure.


User requirements Specification (URS). The set of owner, user and engineering
requirements necessary and sufficient to create a feasible design meeting the intended
purpose of the system.
这几乎奏效了: 关于sub(r'\w(?)? 但它也会删除最后一个和第一个字符…如何避免这种情况

以下是regex101上的相同示例:


由于您的注册表在
\n
之前和之后都匹配
\w
,并且没有将其放回替换位置,因此它会丢失

您可以使用lookarounds作为:

re.sub(r'(?<=\w)\n(?=\w)', ' ')

re.sub(r'(?这与?你可以在正则表达式中使用lookahead和lookahead作为Yes,但他确实回答了我的问题(为什么我将其标记为已解决)-我问错了,它在正则表达式101上工作得很完美(Thx很多).但我不知道我做错了什么-是我缺少的
g
标记吗?这段代码没有什么特别之处。它也可以用于repl.it。只需创建一个新的代码示例并从我的完整ideone代码链接粘贴完整的代码即可。