Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
First off, this tool is a great idea!!!
About this PR:
I added
beginCapture
andendCapture
functions to support capturing groups. Here is an example:To achieve this, I also changed all other
(
used in the code to non-capturing ones(?:
so that the regex wouldn't capture anything the user did not expect.Please be sure to review my changes to the
or
function since I removed the extra check onthis._prefixes
andthis._suffixes
because I couldn't quite figure out what usecase those were addressing.Overall, this pattern is a slight divergence from what you have going right now in that it takes two function calls to achieve something. The other option would be to make it more like
or()
behaves and have acapture()
function that just captures everything before it. However, I thinkbeginCapture()
/endCapture()
is a bit more flexible and allows you to have multiple separate capturing groups which is probably pretty common.Please let me know what you think. I'd be happy to add info to
README.md
and the wiki if you plan on merging it.Thanks,
Oleg
PS - If you like these functions, I was thinking we could even take it a step further and allow users to pass in a
name
intobeginCapture
and then provide a more user-friendly way of accessing the captured values than the array returned byexec()
.