fastmod icon indicating copy to clipboard operation
fastmod copied to clipboard

Cannot use four dash characters as the replacement text

Open Treit opened this issue 4 months ago • 3 comments

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.

Treit avatar Jul 30 '25 18:07 Treit

Can you confirm that you added the files you wanted to search within after the -- at the end of the command line?

nk9 avatar Sep 27 '25 18:09 nk9

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

nk9 avatar Sep 30 '25 21:09 nk9

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.

nk9 avatar Sep 30 '25 22:09 nk9