- [Instuctor] In this self check
we have two exercises for you.
In the first case, we'd like you to replace every occurrence
of one or more tab characters with a comma and a space.
And in the second case we'd like you to split the string
that you see down below here.
And we want you to do that at any sequence of one
or more adjacent $ characters in the string.
So, go ahead and try those exercises
and then come back to see the result.
Okay, let's go ahead and import the re module here,
and here is the answer to the first exercise.
We're going to be replacing the tabs
in the string with comma and space characters,
and here is the regular expression that we're going to use.
Notice the raw string literal
because of the \ character here,
so \t is the escape sequence for a tab character,
and we're saying that we are going
to look for any sequence of one or more tab characters,
and replace them with comma spaces.
So, we have one tab character,
then we have two tab characters,
then we have three tab characters.
And when we execute that, you can see now,
we have a uniformly formatted comma delimited list
with comma spaces separating each value
in the string result.
Now for the other exercise here,
let's go ahead and reveal the answer.
So again, we're splitting on one or more
of the $ characters, so \$
because $ is a regular expression metacharacter.
That was one of the characters that was listed previously
in the metacharacters list that we showed you
towards the beginning
of the regular expressions presentation.
And here again, + means one or more, so we have one $,
and we have two $, so when we split that
we get '123', 'Main', and 'Street',
as three separate strings in the resulting list.