kevinushey/rex — pull request #3 by jimhester (2014-09-23 17:33:52+00:00)
Title: Add match and substitute functions

Add two functions to return matches and perform substitutions from a regex

Still using a pull request because I want your input on how the match function gets matches and returns. (we may be able to use `regmatches` instead for part of this.

As implemented the `match()` function returns different things based on the type of pattern.
1. If there are no capture groups the function returns a logical for each vector in data
2. If there are capture groups it returns a list for each capture group
3. If there are named capture groups it returns a named list
4. If the `g` option is passed a `gregexpr` is used, and a list of lists is returned with the matches

The other thing this function does is automatically prepend any additional options `(?ims)` ect. to the regular expression. We may want to make those options just a function. I originally had them as a match argument because that is how they are specified in perl, but R's implementation is actually slightly more flexible, you can turn the options on and off within a regex.

Please let me know your comments, or modify the function as you see fit!