Releases: tom-lord/regexp-examples
Windows 10 support
Following a raised issue, the gem no longer uses symbolic links to simplify cross-version unicode mappings.
There should be no functional change resulting from this release.
max_results_limit configuration option
Regexp#examples
are now limited to a maximum length of max_results_limit
(default 10000
).
This provides the nice benefit that even for arbitrarily complex patterns, Regexp#examples
will never "freeze" due to it trying to generate an absurdly long list of examples.
However, this is a minor API change: The behaviour of code such as /\w{7}/.examples
has now changed. If you were generating more than 10,000 examples then you must explicitly increase the limit (in this case, to anything >= 78125
), e.g. /\w{7}/.examples(max_results_limit: 100000)
Full Ruby v2.3.x compatibility
This release fixes a few (VERY minor/obscure) bugs caused by differences between v2.3-dev and the new v2.3.0 release.
Probability distribution fix for OrGroups
Previously, due to the way the regex was parsed, the following regex:
/a|b|c|d|e/
Was effectively being treated like:
/a|(b|(c|(d|e)))/
This works perfectly fine for Regexp#examples
, but introduced a subtle bug for use in Regexp#random_example
: The probability of getting each letter is not equal. More specifically, the probability distribution was: a=50%, b=25%, c=12.5%, d=6.25%, e=6.25%
Gem version 1.1.3 fixes this issue, so now examples are chosen with an unbiased randomness (a=20%, b=20%, etc)
Named property definitions added to PStore
Previously, there were 2 main issues with the named properties implementation:
- All definitions for what a named property, e.g.
/\p{Arabic}/
, is defined to match was being stored in RAM (using a ruby hash) at run time. This (slightly) impacted the library load time. - The definitions did not take into account your ruby version. So for example,
/\p{Arabic}/.random_example
may have returned a NON_MATCHING result for ruby 2.0.x/2.1.x
This patch fixes the above, as well as proving much better test coverage, a slight (~10%) overall performance boost for the Regexp#examples
method via lazy evaluation. Also, the test suite has been slightly optimised.
Basically, everything is just a little bit better!
Special thanks to @equivalent for initially proposing this idea, and making the first commits towards my solution :)
Regexp#random_example added
You can now generate one, random, example string (from the set of ALL possible matches!!) for a given regular expression.
Previously, this could have been achieved by doing something like this:
/complicated \w{10} regex/.examples.sample(1)
However, this is horribly inefficient since you must store all 9765625 possible examples in memory before randomly choosing one!
With this new method, even extreme examples like this run relatively quickly:
/\w{1000}/.random_example
This is basically because only ONE example is ever stored in memory, no matter how complicated the regex!
Complete backreference syntax suport
There were two types of backreference syntax support missing; now added:
- Using quotes, instead of angled brackets - e.g.
/(a) \k'1'/.examples
,/(?<name>xyz) \k'name'/.examples
- Using RELATIVE group numbers - e.g.
/(a)(b) \k<-1>/.examples #=> ["abb"]
Also a very obscure bug fix: Using options toggle "groups" should not increment the groups counter - e.g. the following was previously broken; now fixed:
/(?i)(a)-\1/.examples #=> ["a-a", "A-A"]
Negated named properties (\P)
Support already existed for patterns like:
/\p{Space}/.examples
/\p{^Space}/.examples
Now added additional support for negating (or double-negating!) via \P
:
/\P{Space}/.examples
/\P{^Space}/.examples
First production release!
Bumped to v1.0.0 since "all" features are now added! (I.e. The gem is no longer in development.)
The main change since the previous release is a big refactor of char group parsing, which fixes some bugs and allows the use of set intersection - for example the following now work:
/[[a][b][c]]/.examples # => ["a", "b", "c"]
/[[a-h]&&[f-z]]/.examples # => ["f", "g", "h"]
Named properties supported
The following now works:
/\p{^Ll}/.examples # "Not a lower case letter"
With this release, the RegexpExamples::NotYetSupportedSyntax exception has been deleted, since ALL syntax is now (in theory, at least) supported!
There are also a couple of (obscure) bug fixes here, such as /[[:punct:]]/.examples