
黄色部分数字是我想要匹配到的结果(即靠近文字的部分),红色部分是干扰项
若我只想匹配到黄色部分该如何去写正则表达式?
代码第17行是我写的正则,请帮我指出并改正
import docx
from docx.oxml import parse_xml
from docx.oxml.xmlchemy import serialize_for_reading
from docx.oxml.ns import nsmap,qn
import re
path = "2023年10月份人格养成(最初版).docx"
doc = docx.Document(path)
#print(doc.paragraphs[2].text)
paragraphs = doc.paragraphs
print('段落0字体:',paragraphs[0].style.font.name)
print('段落3字体:',paragraphs[3].style.font.name)
#print(paragraphs[1]._p.xml)
#find = re.findall(".*<w:t>(.*?)</w:t>",paragraphs[1]._p.xml)
#find = re.findall('w:szCs w:val=\'([1-9]{2})\'(?=.*外国语学院十月份学风建设)',paragraphs[1]._p.xml)
find = re.findall('<w:p>.*?<w:szCs\s+w:val="52"(?=.*外国语学院十月份学风建设).*?<\/w:p>',paragraphs[1]._p.xml)
print(find)
#print(paragraphs[1]._p.xml)
"""with open("1.txt","w",encoding="utf-8") as a:
a.write(paragraphs[1]._p.xml)
print("\n"*2)
with open("2.txt","w",encoding="utf-8") as a:
a.write(paragraphs[2]._p.xml)
print(paragraphs[3]._p.xml)
with open("3.txt","w",encoding="utf-8") as a:
a.write(paragraphs[3]._p.xml)
"""
下面是xml
```xml
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpsCustomData="http://www.wps.cn/officeDocument/2013/wpsCustomData">
<w:pPr>
<w:pStyle w:val="style0"/>
<w:jc w:val="center"/>
<w:rPr>
<w:rFonts w:ascii="宋体" w:cs="宋体" w:eastAsia="宋体" w:hAnsi="宋体"/>
<w:b/>
<w:bCs/>
<w:sz w:val="52"/>
<w:szCs w:val="52"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:rFonts w:ascii="宋体" w:cs="宋体" w:eastAsia="宋体" w:hAnsi="'体" w:hint="eastAsia"/>
<w:b/>
<w:bCs/>
<w:sz w:val="52"/>
<w:szCs w:val="52"/>
</w:rPr>
<w:t>外国语学院十月份学风建设</w:t>
</w:r>
</w:p>
```