python regex not behaving as i think it should

I am trying to sort through a some files using regex expression.

I have a file which contains the two following lines

NET "MBC_ADR_I1<1>" LOC = "R2";
NET "GP_O<7>" LOC = "R20";

I am using the following expression to get one of the lines only

f2MatchLoc = re.search('(LOC)[ ]+=[ ]+["]?({})'.format(f1LocValue), f2Line, re.IGNORECASE)

where f1LocValue = R2. However I’m getting a match on both lines.

I’ve tried to enter the same expression here
regex101.com

which shows that my argument should be correctly formatted


Source: python

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.