-
Notifications
You must be signed in to change notification settings - Fork 20
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 custom regex #9
Comments
👍 |
2 similar comments
👍 |
👍 |
I imagine the difficulty here is the cross-boundary matching... @eugeneware - is that right? If Eugene's constructing a regular expression out of a string you pass, he only needs to keep strlen(search term) data around from the previous chunk to watch for replacements. I would like this too...just saying I wouldn't know how it would be implemented without using a non-native regular expression implementation. I suppose it could support regular expressions but also require you pass it a maximum match length at the same time. // remove html comments up to 1024 chars
// longer comments would not get replaced
.pipe(replaceStream(/<!--(.|\s)*-->/g, '', { max_match_len: 1024 } )) |
@malgorithms max_match_len requirement on custom regexs sounds fine to me, that would solve most cases |
Correct, you could end up buffering the entire stream in memory if you But implementing a maximum match length might be an option, though not On Fri, Apr 25, 2014 at 7:37 AM, Eric Schoffstall
Eugene Ware Phone: +61 3 9955 7041 Noble Samurai Pty Ltd noblesamurai.com http://www.noblesamurai.com/ | eugeneware.com | |
@eugeneware - what do you mean "not deterministic" in this context? That it would be unpredictable based on boundaries? Like, for a simple example, if you decided you wanted to replace I think if you kept a moving window of data of size (max_match_length * 2) and only performed replacements on matches which began in the first half of the window, there wouldn't be any ambiguities. I think. Does that sound right to you? It would swallow up to max_match_length of repeating |
The moving window approach would definitely work. Should be easy enough to On Fri, Apr 25, 2014 at 11:34 PM, Chris Coyne notifications@github.comwrote:
Eugene Ware Phone: +61 3 9955 7041 Noble Samurai Pty Ltd noblesamurai.com http://www.noblesamurai.com/ | eugeneware.com | |
Fair enough! I am unlikely to do this as I no longer need it, but if I get some hobby time... |
I can take this on. I just used this in a project using regex. Here is the changes I made: https://github.com/mehtaphysical/replacestream/tree/add-regex I'll make a pull request so we can create a dialog about it. But first I want to make a test. |
Thanks @mehtaphysical that would be great! |
It would be cool if this supported passing in a regex instead of a string that becomes a regex.
The text was updated successfully, but these errors were encountered: