From 59cb66388a3a1003148c6f98fcc07786988f1b54 Mon Sep 17 00:00:00 2001 From: Rad Suchecki Date: Wed, 31 Jan 2024 13:22:27 +1030 Subject: [PATCH] updated syntax python2->3 07-python-regexs.md --- _episodes/07-python-regexs.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/_episodes/07-python-regexs.md b/_episodes/07-python-regexs.md index 180ea80..e2f228d 100755 --- a/_episodes/07-python-regexs.md +++ b/_episodes/07-python-regexs.md @@ -47,12 +47,12 @@ parts. import re match = re.search(r'\b(\d+) (\w+)', 'word1 1234 word2') if match: - print match.group(0) - print match.span(0) - print match.group(1) - print match.group(2) + print(match.group(0)) + print(match.span(0)) + print(match.group(1)) + print(match.group(2)) else: - print "No Match" + print("No Match") ~~~ {: .language-python} ~~~ @@ -80,7 +80,7 @@ not a word" as the delimiter for the split. ~~~ listOfWords = re.split(r'\W+', 'word_1 $%^ 1234,word2-word3') -print listOfWords +print(listOfWords) ~~~ {: .language-python} ~~~ @@ -100,7 +100,7 @@ Again, both the pattern and replacement/back-reference syntax is as we've learnt import re oldstring = 'Four 123 Five' newstring = re.sub( r'(\w+)\s+(\d+)\s+(\w+)', r'\2-\1-\3', oldstring ) -print newstring +print(newstring) ~~~ {: .language-python} ~~~