Popular recipes tagged "re" but not "text"http://code.activestate.com/recipes/tags/re-text/2010-12-25T00:12:44-08:00ActiveState Code RecipesSimple Regular Expression Tester (Python)
2010-12-25T00:12:44-08:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577517-simple-regular-expression-tester/
<p style="color: grey">
Python
recipe 577517
by <a href="/recipes/users/4174115/">Sunjay Varma</a>
(<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/line/">line</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/quick/">quick</a>, <a href="/recipes/tags/re/">re</a>, <a href="/recipes/tags/regex/">regex</a>, <a href="/recipes/tags/testing/">testing</a>).
Revision 2.
</p>
<p><strong><em>Is it possible to create a simple command line program that I can use to quickly test my regular expressions?</em></strong></p>
<p>Yes it is. This simple regular expression tester uses Python's re module as well as others to quickly allow you to test your regular expression in one go.</p>
<p>TODO:</p>
<ul>
<li>Add Support For Multiple Regular Expression Input</li>
</ul>
<p>Recent Changes:</p>
<ul>
<li>Made the output prettier with a little more whitespace. More bytes, but at least it's easier to read!</li>
</ul>
Automagically dispatch commands using regex token classes (Python)
2009-09-28T03:46:29-07:00Mick Krippendorfhttp://code.activestate.com/recipes/users/4171813/http://code.activestate.com/recipes/576914-automagically-dispatch-commands-using-regex-token-/
<p style="color: grey">
Python
recipe 576914
by <a href="/recipes/users/4171813/">Mick Krippendorf</a>
(<a href="/recipes/tags/command_dispatch_pattern/">command_dispatch_pattern</a>, <a href="/recipes/tags/re/">re</a>, <a href="/recipes/tags/regex/">regex</a>).
Revision 2.
</p>
<p>The <em>(?P<...>...)</em> notation in Python's regular expressions can be viewed as a classification of matched tokens. The names of these classes can be used to dispatch tokens to appropriate handlers:</p>
Regular Expression for generic sequences of symbols (Python)
2009-06-13T09:51:38-07:00Emanuele Ruffaldihttp://code.activestate.com/recipes/users/4170726/http://code.activestate.com/recipes/576806-regular-expression-for-generic-sequences-of-symbol/
<p style="color: grey">
Python
recipe 576806
by <a href="/recipes/users/4170726/">Emanuele Ruffaldi</a>
(<a href="/recipes/tags/adt/">adt</a>, <a href="/recipes/tags/re/">re</a>, <a href="/recipes/tags/regular_expressions/">regular_expressions</a>, <a href="/recipes/tags/sequence/">sequence</a>).
Revision 2.
</p>
<p>Python regular expression are very powerful and efficient and they can be applied to the recognition of different types of sequences. This recipe shows how to match sequences of generic symbol set with the power of regular expression. The code uses a mapping from every entity into a character. The mapping is used both at level of sequence and in the compilation of the regular expression. When the symbol set is small it is possible to efficiently use 8 bit strings instead of full unicode.</p>
uniform matcher( "re pattern" / re / func / dict / list / tuple / set ) (Python)
2009-05-06T06:17:16-07:00denishttp://code.activestate.com/recipes/users/4168005/http://code.activestate.com/recipes/576741-uniform-matcher-re-pattern-re-func-dict-list-tuple/
<p style="color: grey">
Python
recipe 576741
by <a href="/recipes/users/4168005/">denis</a>
(<a href="/recipes/tags/grep/">grep</a>, <a href="/recipes/tags/re/">re</a>, <a href="/recipes/tags/text_processing/">text_processing</a>, <a href="/recipes/tags/uniform/">uniform</a>).
Revision 2.
</p>
<p>matcher() makes a string matcher function from any of:</p>
<ul>
<li>"RE pattern string"</li>
<li>re.compile()</li>
<li>a function, i.e. callable</li>
<li>a dict / list / tuple / set / container</li>
</ul>
<p>This uniformity is simple, useful, a Good Thing.</p>
<p>A few example functions using matchers are here too: grep getfields kwgrep.</p>