You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/written by tom lord/i.random_example #=> "WrITtEN bY tOM LORD"
34
44
```
35
45
36
46
## Installation
@@ -51,7 +61,7 @@ Or install it yourself as:
51
61
52
62
## Supported syntax
53
63
54
-
Short answer: **Everything** is supported, apart from "irregular" aspects of the regexp language -- see [impossible features](#impossible-features-illegal-syntax)
64
+
Short answer: **Everything** is supported, apart from "irregular" aspects of the regexp language -- see [impossible features](#impossible-features-illegal-syntax).
55
65
56
66
Long answer:
57
67
@@ -89,7 +99,7 @@ Long answer:
89
99
## Bugs and Not-Yet-Supported syntax
90
100
91
101
* There are some (rare) edge cases where backreferences do not work properly, e.g. `/(a*)a* \1/.examples` - which includes "aaaa aa". This is because each repeater is not context-aware, so the "greediness" logic is flawed. (E.g. in this case, the second `a*` should always evaluate to an empty string, because the previous `a*` was greedy! However, patterns like this are highly unusual...)
92
-
* Some named properties, e.g. `/\p{Arabic}/`, list non-matching examples for ruby 2.0/2.1 (as the definitions changed in ruby 2.2). This will be fixed in version 1.1.0 (see the pending pull request)!
102
+
* Some named properties, e.g. `/\p{Arabic}/`, list non-matching examples for ruby 2.0/2.1 (as the definitions changed in ruby 2.2). This will be fixed in version 1.1.1 (see the pending pull request)!
93
103
94
104
Since the Regexp language is so vast, it's quite likely I've missed something (please raise an issue if you find something)! The only missing feature that I'm currently aware of is:
_**WARNING**: Choosing huge numbers, along with a "complex" regex, could easily cause your system to freeze!_
153
+
_**WARNING**: Choosing huge numbers for `Regexp#examples`, along with a "complex" regex, could easily cause your system to freeze!_
140
154
141
155
For example, if you try to generate a list of _all_ 5-letter words: `/\w{5}/.examples(max_group_results: 999)`, then since there are actually `63` "word" characters (upper/lower case letters, numbers and "\_"), this will try to generate `63**5 #=> 992436543` (almost 1 _trillion_) examples!
142
156
143
157
In other words, think twice before playing around with this config!
144
158
145
-
A more sensible use case might be, for example, to generate one random 1-4 digit string:
159
+
A more sensible use case might be, for example, to generate all 1-4 digit strings:
Due to code optimisation, this is not something you need to worry about (much) for `Regexp#random_example`. For instance, the following takes no more than ~ 1 second on my machine:
148
164
149
-
(Note: I may develop a much more efficient way to "generate one example" in a later release of this gem.)
* Use of lambdas/something (in [constants.rb](lib/regexp-examples/constants.rb)) to improve the library load time. See the pending pull request.
155
171
* (Maybe?) add a `max_examples` configuration option and use lazy evaluation, to ensure the method never "freezes".
156
-
* Potential future feature: `Regexp#random_example` - but implementing this properly is non-trivial, due to performance issues that need addressing first!
157
172
* Write a blog post about how this amazing gem works! :)
0 commit comments