Hello, in this video, we are going to look at the amazing red X method of search and we placed in the method exactly cause sub, but allows us to search and replace and delete stuff within strings, which is really, really important. So first of all, let's create a string, some call it string, one equals, so what I'm going to do is for random, just characters number. All of this will come clear while you're doing this very well. So we've got this string right here. And what we want to do is essentially just eliminate or emotionally get some input from the user. We only want numbers, we want to eliminate all non number values.
You can do that by putting in I'm going to return is built in keyword called result equals or we call. So this is the pattern. And the pattern is going to be backslash D. And like I said, there's a link with the videos of regex in this series to cover the different patterns that you can use. You can do patterns to match the end of a string to match non word characters. If you understand what we're covering here, all of the other pattern will be easy to use if you go and check it out to the provided. Okay, so searching and replacing, so we're going to get rid of all digits.
And what we're going to do is for this we just put enter quotation marks, and we just simply pass in our string so string one we won Now what we're gonna do is print out result. So let's run it and see what we get. There we go, all of the extra characters have been removed. Let me show you something. If I printed this off now like this, but instead I've got three parameters. So the first one is the pattern, as we've already covered.
The last one is the string that we're, you know, searching on placing it. This one is a sense of what we're replacing it with, because we've got nothing there and replace it with nothing, replace base and run it. every instance, it gets replaced with a space, sometimes multiple non digit caters, so there's multiple spaces. If we wanted to replace it with less than a dot, for example, we could easily do so there Go now. I think that looks pretty darn hacky and cool. So that's it for this video on searching and replacing you can go further you can delete stuff, you can do all crazy sorts of stuff with the sub method.
Feel free to have a go. I look forward to seeing you in the next video.