Learn Python in One Hour by Victor R. Volkman
Author:Victor R. Volkman
Language: eng
Format: epub
Publisher: Loving Healing Press Inc.
So we’ve solved two out of three criteria with this simple two-character regular expression (“to”): it matches all permutations of mixed-case including “TO”, “to”, “To” and “tO”, and it works around punctuation such as “to)”. Unfortunately, it found twice as many copies of the token by looking inside tattoo and tool:
"To tattoo (or not to) a tool"
1 2 3 4
Compare this with a brute-force approach of using split(), which is the only tool we had up until now! Isolating all the “to” tokens while ignoring when they appear inside other words would be a really hard problem except for a special character sequence “\b” which does this:
\b Matches the empty string, but only at the beginning or end of a word. A word is defined as a sequence of alphanumeric or underscore characters, so the end of a word is indicated by whitespace or a non-alphanumeric, non-underscore character.
Here’s a short program which marches through all these
1: # Exercise #8: case-insensitive search in regular expression
2: import re
3: regex = r"\bto\b"
4: test_str = "To be (or not to) be a tool."
5: matches = re.finditer(regex, test_str, re.IGNORECASE)
6:
7: for matchNum, match in enumerate(matches):
8: matchNum = matchNum + 1
9: print ("Match %s was found at %d-%d: %s" % (
10: matchNum, match.start(), match.end(), match.group()))
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12523)
Hello! Python by Anthony Briggs(9868)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9758)
The Mikado Method by Ola Ellnestam Daniel Brolund(9748)
Dependency Injection in .NET by Mark Seemann(9294)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8259)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7742)
Grails in Action by Glen Smith Peter Ledbrook(7668)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7518)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(6746)
Microservices with Go by Alexander Shuiskov(6513)
Practical Design Patterns for Java Developers by Miroslav Wengner(6411)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6389)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6379)
Angular Projects - Third Edition by Aristeidis Bampakos(5769)
The Art of Crafting User Stories by The Art of Crafting User Stories(5300)
NetSuite for Consultants - Second Edition by Peter Ries(5244)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5062)
Kotlin in Action by Dmitry Jemerov(5020)
