I am trying to search following string with characters in a line.
我试图用一行中的字符搜索下面的字符串。
</Connector>
I wrote following code. But it seems it is not finding this string. I understood that these are not metacharacters and hence should be matched automatically. Also, I checked for blanked spaces. But no avail. Can anyone tell what I am doing wrong?
我写了下面的代码。但似乎没有找到这个字符串。我知道这些不是元字符,因此应该自动匹配。另外,我检查了空白的空格。但无济于事。谁能说出我做错了什么?
for line in wim_file:
if re.findall("</Connector>",line):
print('Word Found')
else:
print("Word Not Found!!")
Note: there is another string with following line which should not match.I need to match exact string with '/' character in above mentioned string.
注意:还有另一个字符串,后面的行不应该匹配。我需要在上面提到的字符串中将完全字符串与'/'字符匹配。
<Connector some text>
EDIT: please find below some more lines from text.
编辑:请在下面找到更多文字行。
<Connector RefLabel="70100-01-L" Tolerance="1" UniqueID="WPWDH">
<Property authority="Design" name="PartNumber">H1BB</Property>
<Property authority="Design" name="Part">89</Property>
<Property authority="Design" name="ZTH">1</Property>
<Property authority="Design" name="Base">WSS Class 3</Property>
<Property authority="Design" name="PATHID">H1BB</Property>
</CoordinatedEntity>
</Connector>
1 个解决方案
#1
0
#assuming wim_file is a filepointer
for line in wim_file.readlines():
if re.findall(".*</Connector>.*",line):
print('Word Found')
else:
print("Word Not Found!!")
a slight modification to the regex made me to get the required lines
对正则表达式略有修改使我得到了所需的行
#1
0
#assuming wim_file is a filepointer
for line in wim_file.readlines():
if re.findall(".*</Connector>.*",line):
print('Word Found')
else:
print("Word Not Found!!")
a slight modification to the regex made me to get the required lines
对正则表达式略有修改使我得到了所需的行