Tapatalk

Replace with embedded parentheses

Replace with embedded parentheses

5
NewbieNewbie
5

    Dec 29, 2015#1

    Is there a way to rewrite the following regex so the replacement becomes defined. My understanding is embedded parentheses cause the replacements \1, \2, etc. to become undefined.

    (SVC\*HC(:\w{2,})+):\w(\*)

    Sample entries this should match. The part in red should be deleted in the replacement. I'm trying to guarantee this only occurs on a line with SVC*.

    SVC*HC:S5102:A*49.39*49.39**1~
    SVC*HC:S5102:X*49.39*49.39**1~
    SVC*HC:S5102:AB:B*49.39*49.39**1~
    SVC*HC:S5102:A*49.39*49.39**1~
    SVC*HC:S5102:AB:C*49.39*49.39**1~

    6,685587
    Grand MasterGrand Master
    6,685587

      Dec 29, 2015#2

      Use as search string: (SVC\*HC(?::\w{2,})+):\w(\*)

      ?: immediately after opening parenthesis changes the group from a capturing group to a non-capturing group. Non-capturing groups can be nested in other non-capturing groups or in capturing groups. Non-capturing groups should be always used when back-referencing the string found by the expression inside a group is not needed.
      Best regards from an UC/UE/UES for Windows user from Austria

      5
      NewbieNewbie
      5

        Dec 29, 2015#3

        Thanks Mofi that worked. My replacement was \1\2 and it worked.

        I could've made the asterisk at the end a look ahead and thus just would've needed \1 as the replacement. Thanks for the tip on the embedded parentheses trick.

        (SVC\*HC(?::\w{2,})+):\w(?=\*)