<linkrel="next"title="Easy menu selection tree"href="Contrib-Tree-Select.html"/>
<linkrel="prev"title="Random Name Generator"href="Contrib-Name-Generator.html"/>
</head><body>
<divclass="admonition important">
<pclass="first admonition-title">Note</p>
<pclass="last">You are reading an old version of the Evennia documentation. <ahref="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
<spanclass="c1"># The number can be generated again</span>
</pre></div>
</div>
</section>
<sectionid="importing">
<h2>Importing<aclass="headerlink"href="#importing"title="Permalink to this headline">¶</a></h2>
<olclass="simple">
<li><p>Import the <codeclass="docutils literal notranslate"><spanclass="pre">RandomStringGenerator</span></code> class from the contrib.</p></li>
<li><p>Create an instance of this class taking two arguments:</p>
<ulclass="simple">
<li><p>The name of the gemerator (like “phone number”, “license plate”…).</p></li>
<li><p>The regular expression representing the expected results.</p></li>
</ul>
</li>
<li><p>Use the generator’s <codeclass="docutils literal notranslate"><spanclass="pre">all</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">get</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">remove</span></code> methods as shown above.</p></li>
</ol>
<p>To understand how to read and create regular expressions, you can refer to
<aclass="reference external"href="https://docs.python.org/2/library/re.html">the documentation on the re module</a>.
Some examples of regular expressions you could use:</p>
<ulclass="simple">
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">r"555-\d{3}-\d{4}"</span></code>: 555, a dash, 3 digits, another dash, 4 digits.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">r"[0-9]{3}[A-Z][0-9]{3}"</span></code>: 3 digits, a capital letter, 3 digits.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">r"[A-Za-z0-9]{8,15}"</span></code>: between 8 and 15 letters and digits.</p></li>
<li><p>…</p></li>
</ul>
<p>Behind the scenes, a script is created to store the generated information
for a single generator. The <codeclass="docutils literal notranslate"><spanclass="pre">RandomStringGenerator</span></code> object will also
read the regular expression you give to it to see what information is
required (letters, digits, a more restricted class, simple characters…)…
More complex regular expressions (with branches for instance) might not be
available.</p>
<hrclass="docutils"/>
<p><small>This document page is generated from <codeclass="docutils literal notranslate"><spanclass="pre">evennia/contrib/utils/random_string_generator/README.md</span></code>. Changes to this
file will be overwritten, so edit that file rather than this one.</small></p>
<liclass="nav-item nav-item-this"><ahref="">Pseudo-random generator and registry</a></li>
</ul>
</div>
<divclass="admonition important">
<pclass="first admonition-title">Note</p>
<pclass="last">You are reading an old version of the Evennia documentation. <ahref="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
</div>
<divclass="footer"role="contentinfo">
© Copyright 2023, The Evennia developer community.
Created using <ahref="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.