TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Python from scratch- RegEx

43 pointsby hodbbyabout 13 years ago

5 comments

reuserabout 13 years ago
I applaud your effort. Regex is a valuable skill (really, language) which you will use across languages and programs as it gives you access to an efficient and pretty general method for scanning and extracting things from text. And if you study fundamentals of computer science (like the Chomsky hierarchy) you will also find that regular expressions are important there too.
评论 #3676835 未加载
lutuspabout 13 years ago
&#62; I would expect Repetition to act like Wildcards but ' + ' is not a wildcard.<p>The meaning of the term "wildcard" may be ambiguous. The plus sign, called a "repetition operator", is used to modify what precedes it, like this:<p>\w+ will match one or more word characters. Word characters are usually in the set A-Z, a-z, 0-9 and the underscore.<p>In much the same way, \w* will match zero or more word characters.<p>And \w? will match zero or one word characters.<p>If you want to use one of these repetition operators in your search, preceded it with a reverse slash:<p>"true\?" will match "true" followed by a question mark, while "true?" will match "tru" optionally followed by "e".
评论 #3675914 未加载
aristusabout 13 years ago
For a good nerdy time, check out the first implementations of glob and regexp. 20 years on they still work in modern Pythons. Soon after Guido decided to make globs a special case of regexp, and his elegant recursive code was no more.<p><a href="http://svn.python.org/view/python/trunk/Lib/glob.py?revision=2268&#38;view=markup" rel="nofollow">http://svn.python.org/view/python/trunk/Lib/glob.py?revision...</a><p><a href="http://svn.python.org/view/python/trunk/Lib/sre_compile.py?revision=14919&#38;view=markup" rel="nofollow">http://svn.python.org/view/python/trunk/Lib/sre_compile.py?r...</a>
js2about 13 years ago
In case you're curious, here's what I consider a modern pythonic solution - <a href="https://gist.github.com/1995010" rel="nofollow">https://gist.github.com/1995010</a>
评论 #3679015 未加载
rhizome31about 13 years ago
PEP8 recommends 4 spaces for indentation. At least you should try to make it consistent.
评论 #3678950 未加载