Announcement

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

  • Remove part elements of local list using regular expressions

    Hi,

    I have a local variable list that I would like to remove the prefixes. The list looks like this

    Code:
    local variables "i.Sex ib5.age10cat i.Inkomst_cat_Yearpresurgery i.Utb_cat_Yearpresurgery i.grpci i.FUNKTIONSBEDOMNING_ASA ib12.type_of_surgery_10cat i.Hospsize_cat d_age_operation elixsum "
    My preferred result would look like this:
    Code:
    local variables_clean "Sex age10cat Inkomst_cat_Yearpresurgery Utb_cat_Yearpresurgery grpci FUNKTIONSBEDOMNING_ASA type_of_surgery_10cat Hospsize_cat d_age_operation elixsum "

    I have tried the following, however the variable i.grpci looses the "i" in the end.

    Code:
    local variables "i.Sex ib5.age10cat i.Inkomst_cat_Yearpresurgery i.Utb_cat_Yearpresurgery i.grpci i.FUNKTIONSBEDOMNING_ASA ib12.type_of_surgery_10cat i.Hospsize_cat d_age_operation elixsum "
    di "`variables'"
    local variables_clean = ustrregexra("`variables'", "i[^\.]*\.", "", .)
    di "`variables_clean'"

    Any suggestions?

    Best regards, Jesper

  • #2
    Code:
    local variables "i.Sex ib5.age10cat i.Inkomst_cat_Yearpresurgery i.Utb_cat_Yearpresurgery i.grpci i.FUNKTIONSBEDOMNING_ASA ib12.type_of_surgery_10cat i.Hospsize_cat d_age_operation elixsum "
    local variables = "`=ustrregexra("`variables'", "\bi\.\b|\bib[\d]+\.\b","")'"

    Res.:
    Code:
    . di "`variables'"
    Sex age10cat Inkomst_cat_Yearpresurgery Utb_cat_Yearpresurgery grpci FUNKTIONSBEDOMNING_ASA type_of_surgery_10cat Hospsize_cat d_age_operation elixsum

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      Code:
      local variables "i.Sex ib5.age10cat i.Inkomst_cat_Yearpresurgery i.Utb_cat_Yearpresurgery i.grpci i.FUNKTIONSBEDOMNING_ASA ib12.type_of_surgery_10cat i.Hospsize_cat d_age_operation elixsum "
      local variables = "`=ustrregexra("`variables'", "\bi\.\b|\bib[\d]+\.\b","")'"

      Res.:
      Code:
      . di "`variables'"
      Sex age10cat Inkomst_cat_Yearpresurgery Utb_cat_Yearpresurgery grpci FUNKTIONSBEDOMNING_ASA type_of_surgery_10cat Hospsize_cat d_age_operation elixsum
      Superfast and super-great answer. Many thanks.

      Comment

      Working...
      X