Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 27th, 2012  |  syntax: None  |  size: 0.48 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Weird regular pattern behaviour in Python
  2. import re
  3.  
  4. data = '''component FA_8 is
  5. port(   a : in bit_vector(7 downto 0);
  6.     b: in bit_vector(7 downto 0);
  7.     s: out bit_vector(7 downto 0);
  8.     c: out bit);
  9. end component;'''
  10.  
  11. m = re.search(r'''component +(w+) +is[ n]+
  12.                 port *[(] +''', data, re.I | re.VERBOSE)
  13.  
  14. if m:
  15.     print m.group()
  16. else:
  17.     print "Cant find pattern"
  18.        
  19. m = re.search(r'''components+(w+)s+iss+
  20.             ports*[(]s+''', data, re.I | re.VERBOSE)