From the course: NLP with Python for Machine Learning Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Regular expression replacements

Regular expression replacements - Python Tutorial

From the course: NLP with Python for Machine Learning Essential Training

Start my 1-month free trial

Regular expression replacements

- [Instructor] Picking up right where we left off, understanding how regx can be used for tokenization is helpful, but let's explore another usage of regx's. So I've defined a sentence here, I want to follow pep8 guidelines. If you're not aware, pep8 is a style guide for Python. Now let's just say this sentence lies in some very large document that you've put together. And you realize that a lot of people don't know what pep8 means. So you want to expand it to pep8 Python style guide. However, let's assume that it's also likely that you made some spelling errors, so instead of pep8, maybe you had pep7, or peep8, which are represented by these other two test strings. So you don't really feel comfortable explicitly searching for pep8 and then replacing that with pep8 Python style guide, because you'll miss these mistakes. So you need to come up with a pattern that will not only capture pep8, but also your mistakes. So we want to build a process that will identify every place where pep8…

Contents