Cannot use four dash characters as the replacement text
I want to replace three dashes on a line by themselves with four dashes across a large number of markdown files.
I tried this command:
fastmod "^\-\-\-\s+" "----" --
However, it fails with:
error: Found argument '--' which wasn't expected, or isn't valid in this context
USAGE:
fastmod.exe [FLAGS] [OPTIONS] <REGEX> <subst> [--] [FILE OR DIR]...
For more information try --help
I could not figure out a work-around to get this to work.
Can you confirm that you added the files you wanted to search within after the -- at the end of the command line?
Huh, this is unrelated to the -- part of the provided command line, and it's not Windows specific. I'm on macOS:
$ fastmod "^\-\-\-\s+" "----" file.txt
error: Found argument '--' which wasn't expected, or isn't valid in this context
USAGE:
fastmod [FLAGS] [OPTIONS] <REGEX> <subst> [--] [FILE OR DIR]...
For more information try --help
The solution is to put two hyphens into your command line like this:
fastmod "^\-\-\-\-\s+" -- "----" file.txt
That flag tells clap to treat everything that comes after as a positional argument. This means that any flags/options you want to pass will need to come before that.
Note that you're probably going to want to change your pattern, because currently it's removing the newline at the end of the line, meaning the replacement diff looks like this (note the spaces after the first four hyphens:
- ----
- test: true
+ ----test: true
----
I think this can be closed.