README.md in regexp-examples-1.0.1 vs README.md in regexp-examples-1.0.2

- old
+ new

@@ -3,11 +3,11 @@ [![Build Status](https://travis-ci.org/tom-lord/regexp-examples.svg?branch=master)](https://travis-ci.org/tom-lord/regexp-examples/builds) [![Coverage Status](https://coveralls.io/repos/tom-lord/regexp-examples/badge.svg?branch=master)](https://coveralls.io/r/tom-lord/regexp-examples?branch=master) Extends the Regexp class with the method: Regexp#examples -This method generates a list of (some\*) strings that will match the given regular expression +This method generates a list of (some\*) strings that will match the given regular expression. \* If the regex has an infinite number of possible srings that match it, such as `/a*b+c{2,}/`, or a huge number of possible matches, such as `/.\w/`, then only a subset of these will be listed. For more detail on this, see [configuration options](#configuration-options). @@ -20,13 +20,19 @@ /this|is|awesome/.examples #=> ['this', 'is', 'awesome'] /https?:\/\/(www\.)?github\.com/.examples #=> ['http://github.com', # 'http://www.github.com', 'https://github.com', 'https://www.github.com'] /(I(N(C(E(P(T(I(O(N)))))))))*/.examples #=> ["", "INCEPTION", "INCEPTIONINCEPTION"] /\x74\x68\x69\x73/.examples #=> ["this"] -/\u6829/.examples #=> ["栩"] /what about (backreferences\?) \1/.examples #=> ['what about backreferences? backreferences?'] +/ + \u{28}\u2022\u{5f}\u2022\u{29} + | + \u{28}\u{20}\u2022\u{5f}\u2022\u{29}\u{3e}\u2310\u25a0\u{2d}\u25a0\u{20} + | + \u{28}\u2310\u25a0\u{5f}\u25a0\u{29} +/x.examples #=> ["(•_•)", "( •_•)>⌐■-■ ", "(⌐■_■)"] ``` ## Installation Add this line to your application's Gemfile: @@ -43,10 +49,14 @@ $ gem install regexp-examples ## Supported syntax +Short answer: **Everything** is supported, apart from "irregular" aspects of the regexp language -- see [impossible features](#impossible-features-illegal-syntax) + +Long answer: + * All forms of repeaters (quantifiers), e.g. `/a*/`, `/a+/`, `/a?/`, `/a{1,4}/`, `/a{3,}/`, `/a{,2}/` * Reluctant and possissive repeaters work fine, too, e.g. `/a*?/`, `/a*+/` * Boolean "Or" groups, e.g. `/a|b|c/` * Character sets, e.g. `/[abc]/` - including: * Ranges, e.g.`/[A-Z0-9]/` @@ -55,36 +65,37 @@ * POSIX bracket expressions, e.g. `/[[:alnum:]]/`, `/[[:^space:]]/` * Set intersection, e.g. `/[[a-h]&&[f-z]]/` * Escaped characters, e.g. `/\n/`, `/\w/`, `/\D/` (and so on...) * Capture groups, e.g. `/(group)/` * Including named groups, e.g. `/(?<name>group)/` - * ...And backreferences(!!!), e.g. `/(this|that) \1/` `/(?<name>foo) \k<name>/` - * Groups work fine, even if nested or optional, e.g. `/(even(this(works?))) \1 \2 \3/`, `/what about (this)? \1/` + * And backreferences(!!!), e.g. `/(this|that) \1/` `/(?<name>foo) \k<name>/` + * ...even for the more "obscure" syntax, e.g. `/(?<future>the) \k'future'/`, `/(a)(b) \k<-1>/`` + * ...and even if nested or optional, e.g. `/(even(this(works?))) \1 \2 \3/`, `/what about (this)? \1/` * Non-capture groups, e.g. `/(?:foo)/` * Comment groups, e.g. `/foo(?#comment)bar/` * Control characters, e.g. `/\ca/`, `/\cZ/`, `/\C-9/` * Escape sequences, e.g. `/\x42/`, `/\x5word/`, `/#{"\x80".force_encoding("ASCII-8BIT")}/` * Unicode characters, e.g. `/\u0123/`, `/\uabcd/`, `/\u{789}/` * Octal characters, e.g. `/\10/`, `/\177/` * Named properties, e.g. `/\p{L}/` ("Letter"), `/\p{Arabic}/` ("Arabic character") -, `/\p{^Ll}/` ("Not a lowercase letter"), `\P{^Canadian_Aboriginal}` ("Not not a Canadian aboriginal character") +, `/\p{^Ll}/` ("Not a lowercase letter"), `/\P{^Canadian_Aboriginal}/` ("Not not a Canadian aboriginal character") * **Arbitrarily complex combinations of all the above!** * Regexp options can also be used: * Case insensitive examples: `/cool/i.examples #=> ["cool", "cooL", "coOl", "coOL", ...]` * Multiline examples: `/./m.examples #=> ["\n", "a", "b", "c", "d"]` * Extended form examples: `/line1 #comment \n line2/x.examples #=> ["line1line2"]` * Options toggling supported: `/before(?imx-imx)after/`, `/before(?imx-imx:subexpr)after/` ## Bugs and Not-Yet-Supported syntax -* 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... +* 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...) * 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)! -There are also some various (increasingly obscure) unsupported bits of syntax; some of which I haven't yet investigated. Much of this is not even mentioned in the ruby docs! Full documentation on all the intricate obscurities in the ruby (version 2.x) regexp parser can be found [here](https://raw.githubusercontent.com/k-takata/Onigmo/master/doc/RE). To name a few: +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: * Conditional capture groups, e.g. `/(group1)? (?(1)yes|no)/.examples` (which *should* return: `["group1 yes", " no"]`) -* Back reference by relative group number, e.g. `/(a)(b)(c)(d) \k<-2>/.examples` (which *should* return: `["abcd c"]`) -* Back reference using single quotes, and for group numbers, e.g. `/(a) \k'1'/.examples` (which is really just alternative syntax for `/(a) \1/`!) + +Some of the most obscure regexp features are not even mentioned in the ruby docs! However, full documentation on all the intricate obscurities in the ruby (version 2.x) regexp parser can be found [here](https://raw.githubusercontent.com/k-takata/Onigmo/master/doc/RE). ## Impossible features ("illegal syntax") The following features in the regex language can never be properly implemented into this gem because, put simply, they are not technically "regular"! If you'd like to understand this in more detail, there are many good blog posts out on the internet. The [wikipedia entry](http://en.wikipedia.org/wiki/Regular_expression)'s not bad either.