简体   繁体   中英

non metacharacters to match using regex

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>
#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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM