Skip to content

Commit

Permalink
updated syntax python2->3 07-python-regexs.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rsuchecki authored Jan 31, 2024
1 parent 2c00494 commit 59cb663
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions _episodes/07-python-regexs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
~~~
Expand Down Expand Up @@ -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}
~~~
Expand All @@ -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}
~~~
Expand Down

0 comments on commit 59cb663

Please sign in to comment.