Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate set of all possible matches for a given regex
    primarykey
    data
    text
    <p><strong>I'm wondering how to find a set of all matches to a given regex with a finite number of matches.</strong></p> <p>For example:</p> <p><em>All of these example you can assume they start with <code>^</code> and end with <code>$</code></em></p> <pre><code>`hello?` -&gt; (hell, hello) `[1-9][0-9]{0,3}` -&gt; (1,2,3 ..., 9998, 9999) `My (cat|dog) is awesome!` -&gt; (My cat is awesome!, My dog is awesome!) `1{1,10}` -&gt; (1,11, ..., 111111111, 1111111111) `1*` -&gt; //error `1+` -&gt; //error `(1|11){2}` -&gt; (1,11,111,1111) //notice how it doesn't repeat any of the possibilities </code></pre> <p>I'd also be interested if there was a way of retrieving count a unique a solutions to the regex or if there is a way to determine if the regex has a finite solutions.</p> <p>It would be nice if the algorithm could parse any regex, but a powerful enough subset of the regex would be fine.</p> <p>I'm interested in a PHP solution to this problem, but other languages would also be fine.</p> <p>EDIT:</p> <p>I've learned in my Formal Theory class about <a href="http://en.wikipedia.org/wiki/Deterministic_finite-state_machine" rel="nofollow noreferrer">DFA</a> which can be used to implement regex (and other regular languages). If I could transform the regex into a DFA the solution seems fairly straight forward to me, but that transformation seems rather tricky to me.</p> <p>EDIT 2:</p> <p>Thanks for all the suggestions, <a href="https://stackoverflow.com/questions/7614962/create-set-of-all-possible-matches-for-a-given-regex#7656789">see my post about the public github project</a> I'm working on to "answer" this question.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload