Popular recipes by Emanuele Ruffaldi http://code.activestate.com/recipes/users/4170726/2009-06-13T09:51:38-07:00ActiveState Code RecipesRegular 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>