Python - Regular Expressions

From PeformIQ Upgrade
Revision as of 14:53, 21 April 2008 by PeterHarding (talk | contribs) (New page: =Using the re Module= <pre> #!/usr/bin/env python #-------------------------------------------------------------------------- import re ... if re.match('esb:', node_name): (na...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Using the re Module

#!/usr/bin/env python
#--------------------------------------------------------------------------

import re

...

   if re.match('esb:', node_name):
      (name, cnt) = re.subn('esb:', '', node_name)
      setattr(service, name, value)
      print "service.__dict__ -> '%s'" % service.__dict__
      return

   if re.match('ns0:', node_name):
      (name, cnt) = re.subn('ns0:', '', node_name)