Advertisement
obernardovieira

Get parts of string (regex)

Nov 20th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import re
  4. vers = "VERSION.PROGRAM:program_name\nVERSION.SUBPROGRAM:sub_program_name"
  5. matchObj = re.match( 'VERSION.PROGRAM:(.*)\nVERSION.SUBPROGRAM:(.*)', vers, re.M|re.I);
  6. if matchObj:
  7.    print ("matchObj.group() : ", matchObj.group())
  8.    print ("matchObj.group(1) : ", matchObj.group(1))
  9.    print ("matchObj.group(2) : ", matchObj.group(2))
  10. else:
  11.    print ("No match!!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement