Merged
Conversation
Owner
|
Thanks very much for this change! And thanks for taking the time to create tests too. Everything looks good. Merged. Also incremented version to 0.2 as it's a new feature. |
Contributor
Author
|
Thank you :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 there.
Background: I've been experimenting with finding and replacing Unicode words in the DOM. Traditionally one would use the word boundary metacharacter (\b) to match words, but that only works for ASCII characters, so I've created a regular expression that matches Unicode words but it requires the use of capture groups.
Solution: I've modified this script slightly to support capture groups. I've added an additional argument that specifies which capture group to use in the match. This allows you to do something like:
.. where it will match 'TESThello' but it will only replace 'TEST'.
I've had to drop using regex.lastIndex as that doesn't fit when using capture groups. Instead I'm using match.index and determining the index of the capture group within the match. NOTE: This also fixes a bug when running non-greedy regexes. Previously you were using indexOf to find the index of a match:
... that will break if using a word boundary in your regex, with the following example: /\bat\b/ : 'matching at'
I've added tests for both the capture groups and word boundaries non-greedy matches.
Please let me know what you think of this change.