Be Case-Insensitive
00:00
Now let’s take care of the swear words. And for this, you will again use the \w*
character. Just like before with the \w*
, you’ll find different cases of the swear words. So not just blast, but also blasted, or if this would be the case in your transcript, you would find blasting and so on.
00:21 So remove everything except
00:28 And as you can see now, your regular expression matches any alphanumerical character. That’s cool to see. However, that’s not what you want. What you want is to look for the word blast.
00:42
And now something interesting is happening. You added the word blast, but you don’t have a match. And that’s something you may remember from the .replace()
method.
00:52
You really need to be specific what you are looking for. In the regular expression input string, you have a lowercase string with blast
, but in your test string, there is either BLASTED
in uppercase or Blast
with a uppercase character.
01:06 And that’s the moment where you should have a look at the options on the right side of the input field. As you will learn soon, regular expression options, which are named flags, can give you more control about the regular expression you’re using.
01:21
Currently, you have global and multi line activated, and that’s why your multiline string works as a test string, but you haven’t selected insensitive so that you look for case-insensitive matches. So once you select it, you will see that the regular expression successfully now finds BLASTED
in uppercase or Blast
with a uppercase B
at the beginning. And again, the \w*
helps you to find not just the word blast, but also the word blasted.
01:52 Or you would find words like blasting or blastalicious. So that’s the cool thing about regular expressions. You are looking for patterns. Again, copy this regular expression and paste it in a text file because you will need it in a moment.
Become a Member to join the conversation.