Affects Version/s: None
Fix Version/s: None
The re-matches function does not have the correct semantics: it performs a search (not match) against the string and returns nil if the string and matched-string are unequal. This is not the same as true matching, which is like inserting "^" and "$" at the beginning and end of the pattern.
Example in Clojure:
This bug is (one of the) reasons why
I'm not completely sure what to do here. My first thought is to have re-matches inspect the -source property of its regex input, wrap the string with "^$", then carefully copy all flags over to a new regexp.
- Are there any valid patterns where this is not safe? E.g., where we could not put ^ first? Is "^^abc$$" ok?
- Can we avoid cloning if ^ and $ are already the first and last chars of the pattern?
- How does multiline mode play in to this, if at all?
- regexinstance.lastIndex is a piece of mutability on regex instances (or the RegExp global on older browsers) which is used as a string offset for multiple invocations of exec() on the same string. I have no idea what to do if re-* gets a regex with the global flag set. (BTW, this is a very good reason to reject
CLJS-150: allowing clojure to accept the global flag makes regular expression objects stateful, and would completely screw up re-seq for example.)