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.

Building a DNA Regex Search Engine

9 pointsby sajithwabout 9 years ago

1 comment

dalkeabout 9 years ago
&gt; It turned out finding a Python library to parse regexes (and not parse using regexes) was surprisingly difficult. You could use the debug flag (re.compile(regex, re.DEBUG)) to see the AST it parses, but 1) it prints to stdout and 2) we&#x27;d need to reparse it again to get our own AST, so it seemed too hacky of an approach:<p>One option is to use the internal and undocumented sre_parse module:<p><pre><code> &gt;&gt;&gt; sre_parse.parse(&quot;[AB]C[D-F](G|H)&quot;) [(&#x27;in&#x27;, [(&#x27;literal&#x27;, 65), (&#x27;literal&#x27;, 66)]), (&#x27;literal&#x27;, 67), (&#x27;in&#x27;, [(&#x27;range&#x27;, (68, 70))]), (&#x27;subpattern&#x27;, (1, [(&#x27;in&#x27;, [(&#x27;literal&#x27;, 71), (&#x27;literal&#x27;, 72)])]))] </code></pre> It&#x27;s been stable for 10-15 years, and the above works in 2.x and 3.x.