Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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 REGEXP是否用模式本身和替换替换已识别的模式?_Python_Regex_Matching - Fatal编程技术网

PYTHON REGEXP是否用模式本身和替换替换已识别的模式?

PYTHON REGEXP是否用模式本身和替换替换已识别的模式?,python,regex,matching,Python,Regex,Matching,文本- .1。这真是太棒了。谷歌刚刚毁了苹果。苹果毁了自己 图案=(点)(数字)(点)(单空格) 假设在上述模式中有30到40个带有段落编号的句子。段落编号后面应替换标签使用re.sub() 我希望文本是: </p> <p style="text-align: justify;">1. This is just awesome.</p> <p style="text-align: justify;">2. Google just ruined Ap

文本-

.1。这真是太棒了。谷歌刚刚毁了苹果。苹果毁了自己 图案=(点)(数字)(点)(单空格)

假设在上述模式中有30到40个带有段落编号的句子。段落编号后面应替换
标签使用
re.sub()

我希望文本是:

</p> <p style="text-align: justify;">1. This is just awesome.</p> <p style="text-align: justify;">2. Google just ruined Apple.</p> <p style="text-align: justify;">3. Apple ruined itself!

1。这真是太棒了。

2。谷歌刚刚毁了苹果。

3。苹果毁了自己!


这就是匹配组在正则表达式中的作用

你想要的是这样的:

new_string = re.sub(r'\.(\d+\. )', '</p><p style="text-align: justify;">\\1', old_string)
new\u string=re.sub(r'\.(\d+\),'

\\1”,旧\u string)

此文件可能重复: