I have this following program in Python.
import re
data = '''component FA_8 is
port( a : in bit_vector(7 downto 0);
b: in bit_vector(7 downto 0);
s: out bit_vector(7 downto 0);
c: out bit);
end component;'''
m = re.search(r'''component\ +(\w+)\ +is[\ \n]+
port\ *[(]\ +''', data, re.I | re.VERBOSE)
if m:
print m.group()
else:
print "Cant find pattern"
I can’t figure out why it is not working. If I change ending of regular pattern with port\ *[(]\ * then it matches.
If the quantifier is the only difference, then it means that there is no space in the text, could it be that it is a tab in the original string?
I would replace the escaped space by a whitespace
\s.\sis matching a whitespace character, this is a space, a tab,\rand\n(and other whitespace characters)