Ruby Example: Prefix second argument Playground link Source attribute :a, :b, :c, foo, bar attribute :a, :b, :c, :d attribute :a, :b Result attribute :a, :prefix_b, :c, foo, bar attribute :a, :prefix_b, :c, :d attribute :a, :prefix_b Rule rule: any: - pattern: attribute $A, $B, $$$ARGS - pattern: attribute $A, $B fix: attribute $A, $NAME$MAYBE_COMMA$$$ARGS transform: # Idea from https://ast-grep.github.io/guide/rewrite-code.html#add-conditional-text MAYBE_COMMA: replace: by: ', ' replace: ^.+ source: $$$ARGS NAME: replace: by: :prefix_$1 replace: :?(.+) source: $B