Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using regex with subinstr to replace a pattern in variable name

    Hi

    I have the following variables
    1) abc_0 abc_1 abc_2
    2) def_2 def_3 def_4
    3) ghi_00 ghi_1 ghi_2 ghi_3 ghi_4

    I want to convert the variable names to start from 1 and go till "n" where n is the number of variables with the consistent initial variable pattern (i.e abc, def or ghi). So eventually I want the variable list to look like

    1) abc_1 abc_2 abc_3
    2) def_1 def_2 def_3
    3) ghi_1 ghi_2 ghi_3 ghi_4 ghi_5

    What would be the most efficient way to get to this. Reminder - variable names can contain different number of characters so - there could be - jklmn_1 jklmn_2 jklmn_3................jklmn_14

    Thank You
    Last edited by Steph Cheri; 16 Aug 2024, 11:50.

  • #2
    Code:
    rename abc_# abc_# , renumber
    rename def_# def_# , renumber
    rename ghi_# ghi_# , renumber

    Comment


    • #3
      Didn't know about renumber! That worked perfectly! Thank you daniel klein

      Comment

      Working...
      X