Animated regular-expression prime test in faster Regex Powertoy
This
thread at News.YC motivated me to deploy some recent improvements to
Regex Powertoy. It's now noticeably faster, especially for animating regex matching, and 'matchmarks' more reliably capture the entire syntax/display/animate settings.
Considering the prime-testing regex mentioned in the thread:
/^1?$|^(11+?)\1+$/
We can watch this match number 49 -- essentially discovering a factor and confirming that 49 is not prime -- by visiting this matchmark:
/^1?$|^(11+?)\1+$/
1111111111111111111111111111111111111111111111111
We can watch the regex fail to match 47 -- confirming its primality -- with this matchmark:
/^1?$|^(11+?)\1+$/
11111111111111111111111111111111111111111111111
We can further fancy things up by including a substitution string to replace not-prime numbers, and use the 'show edits' highlight mode:
s/^1?$|^(11+?)\1+$/not prime/
1111111111111111111111111111111111111111111111111
Note that clicking on the matched range brings up a detail view showing subgroup matches -- in this case the group's length is the factor found.
Note that Regex Powertoy requires Java -- a hidden applet makes use of Java's better-than-Javascript regex engine. (The recent changes have included replacing an old version of Prototype with the latest jQuery, and minimizing the slow JS-to-Java callouts by returning results in batches.)
Labels: applet, javascript, jquery, prime numbers, regex, regular expressions, rexexp
«»
(0) comments
Regex Powertoy fixes
Some combination of Firefox updates in the 1.5.x range or perhaps Java updates had left
Regex Powertoy in a state where it usually wouldn't initialize properly, leaving it non-functional.
It's been updated with a new way to delay initialization until the necessary background applet is surely available. Also, a couple bugs with replace backreferences and replace matchmarks have been fixed. If it's seemed flaky the last time you tried it, give it another whirl.
(For more background on Regex Powertoy, see this post.)
Labels: powertoy, regex, regexp, regular expressions, tool
«»
(1) comments