Popular recipes tagged "re"http://code.activestate.com/recipes/tags/re/popular/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&lt;...&gt;...)</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> Tripwire policy file creator (Python) 2009-02-25T20:30:15-08:00Bill Sharerhttp://code.activestate.com/recipes/users/4168512/http://code.activestate.com/recipes/576670-tripwire-policy-file-creator/ <p style="color: grey"> Python recipe 576670 by <a href="/recipes/users/4168512/">Bill Sharer</a> (<a href="/recipes/tags/os_walk/">os_walk</a>, <a href="/recipes/tags/re/">re</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/tripwire/">tripwire</a>). </p> <p>gen_twpol.py is a script that can be used to generate a tripwire policy source (twpol.txt) for your system.</p> <p>This script may be distributed under the terms of the Gnu Public License GPLv2 or later.</p> <p>For more information on the open source version of tripwire see <a href="http://sourceforge.net/projects/tripwire/" rel="nofollow">http://sourceforge.net/projects/tripwire/</a></p> <p>The tripwire source package usually ships with a an example twpol.txt file based on a RedHat Enterprise (RHEL) distribution, typically an RHEL4 or RHEL5 version. It doesn't do much good to have this get parked by your Gentoo ebuild (nor other distro packager) as all sorts of stuff in /boot, /lib/modules and other places will be out of sync, differently named or just plain missing. In addition, your system may have extra stuff that isn't present in the file but critical to the distro.</p>