How to get a list of matchable characters from a regex class
<p>Given a regex character class/set, how can i get a list of all matchable characters (in python 3). E.g.:</p>

<pre><code>[\dA-C]
</code></pre>

<p>should give</p>

<pre><code>['0','1','2','3','4','5','6','7','8','9','A','B','C']
</code></pre>

<p>I think what you are looking for is <a href="https://docs.python.org/2/library/string.html#string.printable" rel="nofollow"><code>string.printable</code></a> which returns all the printable characters in Python. For example:</p>

<pre><code>&gt;&gt;&gt; import string
&gt;&gt;&gt; string.printable
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&amp;\'()*+,-./:;&lt;=&gt;?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
</code></pre>

<p>Now to check content satisfied by your regex, you may do:</p>

<pre><code>&gt;&gt;&gt; import re
&gt;&gt;&gt; x = string.printable
&gt;&gt;&gt; pattern = r'[\dA-C]'
&gt;&gt;&gt; print(re.findall(pattern, x))
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C']
</code></pre>

<p><code>string.printable</code> is a combination of <em>digits, letters, punctuation,</em> and <em>whitespace</em>. Also check <a href="https://docs.python.org/2/library/string.html#string-constants" rel="nofollow">String Constants</a> for complete list of constants available with <a href="https://docs.python.org/2/library/string.html" rel="nofollow">string</a> module.</p>

<hr>

<p><em>In case you need the list of all <code>unicode</code> characters</em>, you may do:</p>

<pre><code>import sys
unicode_list = [chr(i) for i in range(sys.maxunicode)]
</code></pre>

<p><strong>Note:</strong> It will be a huge list, and console might get stuck for a while to give the result as value of <code>sys.maxunicode</code> is:</p>

<pre><code>&gt;&gt;&gt; sys.maxunicode
1114111
</code></pre>

<p>In case you are dealing with some specific unicode formats, refer <a href="http://billposer.org/Linguistics/Computation/UnicodeRanges.html" rel="nofollow">Unicode Character Ranges</a> for limiting the ranges you are interested in.</p>

python regex python-3.x