-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for running a callback for non-matches #23
Comments
Ah good point, I like this idea. I think it deserves a bit of thought though. One issue would be that this would mean we can't do #6. Another potential issue is that this sort of API seems pretty uncommon (have any examples of libraries that do something similar?). I'm fully onboard with being able to control non-match output. However, a fourth arg would work but it feels like a quick fix rather than a considered solution. Interested to know what you think @pintocarlos |
Thanks for the reply @iansinnott With regards to #6, could it coexist with this issue by using a negative lookahead of the input regex? Meaning, the negative regex of the input would return the non-matches. Now about the 4th param callback for non-matches, it seemed to me the most natural place to put this callback, but I am open to other suggestions that could also work well. |
What about just adding a second function to this library? The concept of collecting results based on both outcomes of a predicate reminds me of a partition function. Maybe something like stringPartition(input, regex, match, nonMatch) This way it's not a breaking change and doesn't overload the functionality of the replace function any more. |
I see your point. Makes sense. |
Yeah, that's what I'm thinking
|
any updates on this guys? |
Nope, but I'd be happy to merge a PR if anyone wants to open one. |
A 4th parameter as callback to process non-match items would be useful.
For instance, in ReactNative, plain text cannot be outside of
<Text>
components. The non matches need to be wrapped in a component as well. A callback for these would come quite handy.Example:
The text was updated successfully, but these errors were encountered: