![]() The re.finditer(pattern, string) accomplishes this easily by returning an iterator over all match objects. The general idea is to match a line that doesn’t contain the string ‘ 42', print it to the shell, and move on to the next line. You can see that the code successfully matches only the lines that do not contain the string '42'. I’ll show you the code first and explain it afterwards: import reįor match in re.finditer('^((?!42).)*$', s, flags=re.M): Python Regex Superpower – The Ultimate Guideĭo you want to master the regex superpower? Check out my new book The Smartest Way to Learn Regular Expressions in Python with the innovative 3-step approach for active learning: (1) study a book chapter, (2) solve a code puzzle, and (3) watch an educational chapter video.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |