facebookincubator / fastmod

A fast partial replacement for the codemod tool
Apache License 2.0
1.66k stars 41 forks source link

Provide an example that includes `$` in the replacement string. #15

Closed sheki closed 5 years ago

sheki commented 5 years ago

I am working with some hack/php code and it has a lot of $ symbols. I have not found a way to include $ in the replacement code.

The below command

fastmod 'function unfurl_(\w+)\(.*message.*\)' 'function unfurl_${1}(team_t \$team, \$item, UnfurlContext $context)' file.php

Produces this

- function unfurl_unknown(team_t $team, $item, $message, bool $do_link_unfurling, bool $do_media_unfurling): legacy_ret_t {
+ function unfurl_unknown(team_t \, \, UnfurlContext ): legacy_ret_t {
swolchok commented 5 years ago

https://docs.rs/regex/1.2.0/regex/struct.Regex.html#replacement-string-syntax says "to write a literal $, use $$." I'll call this out in our docs because it's not on the main page of the regex crate documentation. Thanks!

swolchok commented 5 years ago

Fixed by d9d917ec9907f6f6b71cce2e5fde0659ac1023b4