sad icon indicating copy to clipboard operation
sad copied to clipboard

[pebcak?/bug] Capture groups not working as expected?

Open lcpichette opened this issue 1 year ago • 0 comments

Minimal reproducible issue

I think I used a pretty simple regex search and replace for my first time using sad, I could be mentally choking, but (job) should be a valid capture group in the search string for text job which can be referred to as $1 in the replace string.

https://github.com/user-attachments/assets/f6cd25d3-1bb6-46c7-80dc-ad9a22a72a2f


Additional context

"Why not just use job instead of $1?" --> I'm trying to make the example as simple as possible. My use-case actually needs something more like ([a-zA-Z\-]+). So I'd like to find a working example that's as close to what I'm actually wanting as possible.

Here's what I need to end up running:

fd '.*\.js' | sad "strapi\.services\.([a-zA-Z\-]*)\.((create)|(update)|(findOne))\(([a-zA-Z\":'\s{}]*)\)" "strapi.entityService.$2('api::$1.$1',$6);"

Here's showing the search and replace pattern working in a teser:

2024-10-22@14 56 23 October-22@2x


Census

Even in the most simple of examples (see below) anything in the search capture group (e.g. (.*) should be usable in the replace string as $n (e.g. $1). So fd '.*\.js' | sad "\.(.*)\." ".$1." -> Should pipe all js files recursively in my current pwd to sad (which it does) and find anything with .<literally anything>. and replace it with .<that same literally anything>. (noop) -- but instead it finds .<literally anything>. (good) and replaces it with .. (as if the capture group is incorrect, but it's the exact same pattern as shown https://github.com/ms-jpq/sad/issues/44#issuecomment-1004741242)

https://github.com/user-attachments/assets/747cdb50-833d-4454-937d-1f9f3e63ff60

lcpichette avatar Oct 22 '24 21:10 lcpichette