Skip to content

Instantly share code, notes, and snippets.

@mortymacs
Created June 11, 2013 06:07
Show Gist options
  • Save mortymacs/5754763 to your computer and use it in GitHub Desktop.
Save mortymacs/5754763 to your computer and use it in GitHub Desktop.
Fetch variables name and value via python script.
import re
pattern = '\$*(?P<var>[a-zA-Z0-9_\.]+)\s*=\s*\'?\"?(?P<value>[a-zA-Z0-9_\+\.]*)\'?\"?'
#pattern = '\$*(?P<var>\w+)\s*=\s*\'?\"?(?P<value>\w*)\'?\"?'
action = re.compile(pattern)
data = '''
$firstname = "Morteza"
$last_name="ipo"
$age=23
name="Morteza"
last_name=ipo
age = 23
status = 'Deactive'
home=''
other=""
'''
print action.findall(data)
@mortymacs
Copy link
Author

another pattern was comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment