+ indep. WoS citations

Python and Networks -- Class notes -- 2016-03-08

1.  Script to test pattern match

1.1  Python code

import re

# find something between A and Z,
# but there is more than one Z to stop
strList = ['A B C D Z X A E F G Z ']

# .+ is greedy, .+? is parsimonious
patternList = ['A(.+)Z', 'A(.+?)Z']

# check match for all strings and patterns
for string in strList:
    for pattern in patternList:
        print "string = %s, pattern = %s, all matches: " % (string, pattern),

        # if there is a match, then print all matches 
        if re.search(pattern, string):
            print re.findall(pattern, string)

        # no match
            print "No match"