Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript regex library with incremental testing
    text
    copied!<p>I'm looking for a JavaScript library (ideally a node.js package) that can check if a string matches a regular expression incrementally (i.e. one character at a time), and return indeterminate results. For example, say I have the following regex:</p> <pre><code>j.*s.* </code></pre> <p>And I want to test the string "javascript". I would like an API similar to the following:</p> <pre><code>var iregex = new IncrementalRegex('j.*s.*'); var matcher = iregex.createMatcher(); matcher.append('j'); matcher.test(); //returns "possible match" matcher.append('a'); matcher.test(); //returns "possible match" matcher.append('v'); matcher.append('a'); matcher.append('s'); matcher.test(); //returns "match found" matcher.append('ript'); matcher.test(); //returns "match found" </code></pre> <p>Whereas if I tested the string "foo", I would expect something like this:</p> <pre><code>var matcher2 = iregex.createMatcher(); matcher.append('f'); matcher.test(); //returns "no match possible" //At this point I wouldn't bother appending "oo" because I know that no match is possible. </code></pre> <p>EDIT: To be clear, append is building up the string being tested. A new matcher starts out testing against the empty string, and after a matcher.append('foo') it matches against foo. appendToString or buildUpString might have been better names to use.</p> <p>Also, I have one idea of how this could potentially be done, but I haven't fully thought it through yet. Perhaps it is possible to build a "Potential match" regex from the original regex that will match strings if and only if they are the beginning of a string the original regex matches.</p>
 

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