Python - Regular Expressions

From PeformIQ Upgrade
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)