Skip to content

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

@lcpichette

Description

@lcpichette

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.

2024-10-22@14.26.11.October-22.mp4

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 #44 (comment))

2024-10-22@14.48.30.October-22.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions