-
Notifications
You must be signed in to change notification settings - Fork 139
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
Bug in replace? Text is removed #44
Comments
@Tragen since Just replace it with |
Thanks for the workaround. |
Ran into same problem, have the same opinion, but I am glad to hear this was at least taken into consideration and not a hidden bug. |
The current behavior follows the https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
I do think we should document this caveat more clearly though, so I'll do that tomorrow |
Maybe there's a thread in the regex crate to discuss it. Probably hard to change the upstream now. As someone with a lot of regex experience across Perl, Python, Ruby, Javascript, Oniguruma, Grep, Sed, etc I've never had an issue figuring out small differences like \1 instead of $1 or \k instead of \g, but it did take me quite a while to figure out what I was supposed to do. Mostly because "sometimes" the $1 worked and other times it didn't and the pattern was not obvious. Documentation would help a bit but honestly, given how common bash/shell is I really doubt any first time user is going to see I feel like a warning would be the most useful thing. Meaning, if a replace involves a capture group that doesn't exist, and the group starts with a number, just explain the whole situation of how to refer to numbered capture groups. |
It dates all the way back to an early regex issue It looks like constructing a named capture starting with an integer is already disallowed by the This will be a breaking change, but I was already planning on making other breaking changes in the next release, so that's fine. Thanks for staying adamant @jeff-hykin |
Glad to hear about it! with old school tools like sed being basically frozen, I feel like its the job of this next generation of CLI tools to be as intuitive as possible before they also eventually become frozen. |
I comment like this: rust-lang/regex#69 (comment):
Do you think it is a better idea? |
Finally got around to handling this. I opted for a hard error when the user passes a capture group name that would be invalid. Here is what the error for the original usage looks like now This means that we're now just a bit more strict than the other regex-related Rust tools that people are familiar with which I think is perfectly fine |
Perfect 👌 thanks! |
I'm using the Windows version 0.65 and this is the command. It's working with many other tools but not with sd.
Test.txt contains this Text
It gets replaced with
I'm Missing the first capture group and the Call word.
Can you tell me if I'm doing something wrong or if it's a bug.
As other tools are working with the same pattern and replace strings, I think it's a bug in sd.
The text was updated successfully, but these errors were encountered: