Skip to content

Commit f1d93c8

Browse files
author
Michael Zingale
committed
regular expressions example
1 parent 05313fb commit f1d93c8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

examples/python-snippets/regex.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import re
2+
3+
strings = [r"<a>this is my string</a>",
4+
r"<b>this is a different string</b>"]
5+
6+
# this is the pattern that we will match -- it has 3 groups
7+
re_test = r"<(\w)>(.*)</(\w)>"
8+
9+
10+
for s in strings:
11+
a = re.search(re_test, s)
12+
13+
if not a == None:
14+
if a.group(1) == a.group(3):
15+
# we found a match
16+
print "string in '{}' tags is: {}".format(a.group(1), a.group(2))
17+
18+
19+

0 commit comments

Comments
 (0)