Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Find John Doe

00:00 All right, let’s get started. First, you need to paste the transcript string into the test string field,

00:08 and that’s basically everything you need to do for the test string. This will be the part where you will see the visualization in a moment. So next, focus on the regular expression input field at the top.

00:19 With regular expressions, you basically create patterns that the regular expression looks for. So, when you write

00:30 johndoe in the regular expression input field, you can see that regex101 already highlights johndoe. That means that the pattern of the regular expression on top is found in the test string. That’s good news for now, but you also want to have the square brackets being found.

00:49 So, when you add the square brackets at the beginning and the end,

00:55 then you see that something weird is happening. Now it’s not only that johndoe is being found, but also different letters in your test string.

01:04 The reason for this is that square brackets are special characters in regular expressions, and that’s where the explanation on the right can help you. regex101 tells you that the square brackets, or your current regular expression pattern, matches a single character present in the list below.

01:24 So with square brackets, you basically create a character set that the regular expression will look out for. That will come in handy in a moment, but for now you want literally square brackets, so that’s why you need to add an escape character just before every square bracket. And the escape character is the same one like in Python, and that’s a backslash (\).

01:47 So once you put the backslash at the beginning of the square brackets, you see that now [johndoe] of your test string is being selected. That’s awesome.

01:57 So you’ve got your first regular expression pattern covered. Select and copy the regular expression and save it into a text file because you will need it in a moment. Okay, so with this regular expression covered, let’s take care of the support_tom username.

Become a Member to join the conversation.