Skip to main content
Added syntax highlighting to explanation
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141
W#Sb&[email protected] KXWb:b@>2.$1b
                             a, b are cmdline args; s is space; XW is `\w` (implicit)
W                            While
 #                            length of
  Sb                          longest suffix of b (the current word)
                              is nonzero (i.e. length of b is at least 2)
    &                        and
       @b                     first character of b
         .s                   concatenated to a space
           .                  concatenated to the following regex...
               XW              word character: \w
              K                with Kleene star operator: \w*
            C                  wrapped in a capture group: (\w*)
     a~                       matches somewhere in a (the definitions)
                             do:
                 b:            Assign to b
                   b@>2        all but the first two characters of b
                       .$1     concatenated to the contents of the regex capture group
                          b  Output the final value of b
W#Sb&[email protected] KXWb:b@>2.$1b
                             ; a, b are cmdline args; s is space; XW is `\w` (implicit)
W                            ; While
 #                           ;  length of
  Sb                         ;  longest suffix of b (the current word)
                             ;  is nonzero (i.e. length of b is at least 2)
    &                        ; and
       @b                    ;  first character of b
         .s                  ;  concatenated to a space
           .                 ;  concatenated to the following regex...
               XW            ;   word character: \w
              K              ;   with Kleene star operator: \w*
            C                ;   wrapped in a capture group: (\w*)
     a~                      ;  matches somewhere in a (the definitions)
                             ; do:
                 b:          ;   Assign to b
                   b@>2      ;   all but the first two characters of b
                       .$1   ;   concatenated to the contents of the regex capture group
                          b  ; Output the final value of b
W#Sb&[email protected] KXWb:b@>2.$1b
                             a, b are cmdline args; s is space; XW is `\w` (implicit)
W                            While
 #                            length of
  Sb                          longest suffix of b (the current word)
                              is nonzero (i.e. length of b is at least 2)
    &                        and
       @b                     first character of b
         .s                   concatenated to a space
           .                  concatenated to the following regex...
               XW              word character: \w
              K                with Kleene star operator: \w*
            C                  wrapped in a capture group: (\w*)
     a~                       matches somewhere in a (the definitions)
                             do:
                 b:            Assign to b
                   b@>2        all but the first two characters of b
                       .$1     concatenated to the contents of the regex capture group
                          b  Output the final value of b
W#Sb&[email protected] KXWb:b@>2.$1b
                             ; a, b are cmdline args; s is space; XW is `\w` (implicit)
W                            ; While
 #                           ;  length of
  Sb                         ;  longest suffix of b (the current word)
                             ;  is nonzero (i.e. length of b is at least 2)
    &                        ; and
       @b                    ;  first character of b
         .s                  ;  concatenated to a space
           .                 ;  concatenated to the following regex...
               XW            ;   word character: \w
              K              ;   with Kleene star operator: \w*
            C                ;   wrapped in a capture group: (\w*)
     a~                      ;  matches somewhere in a (the definitions)
                             ; do:
                 b:          ;   Assign to b
                   b@>2      ;   all but the first two characters of b
                       .$1   ;   concatenated to the contents of the regex capture group
                          b  ; Output the final value of b
Clarification
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141
W#Sb&[email protected] KXWb:b@>2.$1b
                             a, b are cmdline args; s is space; XW is `\w` (implicit)
W                            While
 #                            length of
  Sb                          longest suffix of b (the current word)
                              is nonzero (i.e. length of b is at least 2)
    &                        and
       @b                     first character of b
         .s                   concatenated to a space
           .                  concatenated to the following regex...
               XW              word character: \w
              K                with Kleene star operator: \w*
            C                  wrapped in a capture group: (\w*)
     a~                       matches somewhere in a (the definitions)
                             do:
                 b:            Assign to b
                   b@>2        all but the first two characters of b
                       .$1     concatenated to the contents of the regex capture group
                          b  Output the final value of b
W#Sb&[email protected] KXWb:b@>2.$1b
                             a, b are cmdline args; s is space; XW is `\w` (implicit)
W                            While
 #                            length of
  Sb                          suffix of b (the current word)
                              is nonzero (i.e. length of b is at least 2)
    &                        and
       @b                     first character of b
         .s                   concatenated to a space
           .                  concatenated to the following regex...
               XW              word character: \w
              K                with Kleene star operator: \w*
            C                  wrapped in a capture group: (\w*)
     a~                       matches somewhere in a (the definitions)
                             do:
                 b:            Assign to b
                   b@>2        all but the first two characters of b
                       .$1     concatenated to the contents of the regex capture group
                          b  Output the final value of b
W#Sb&[email protected] KXWb:b@>2.$1b
                             a, b are cmdline args; s is space; XW is `\w` (implicit)
W                            While
 #                            length of
  Sb                          longest suffix of b (the current word)
                              is nonzero (i.e. length of b is at least 2)
    &                        and
       @b                     first character of b
         .s                   concatenated to a space
           .                  concatenated to the following regex...
               XW              word character: \w
              K                with Kleene star operator: \w*
            C                  wrapped in a capture group: (\w*)
     a~                       matches somewhere in a (the definitions)
                             do:
                 b:            Assign to b
                   b@>2        all but the first two characters of b
                       .$1     concatenated to the contents of the regex capture group
                          b  Output the final value of b
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

Pip, 27 bytes

W#Sb&[email protected] KXWb:b@>2.$1b

Try it here! Or, here's a 28-byte equivalent in Pip Classic: Try it online!

The tag definitions and the initial word are taken as command-line arguments. Each definition is given as alphabet symbol + space + string, and definitions are separated by any non-space non-alphanumeric symbol. For example:

a bc;b a;c aaa

This will need to be quoted so the command-line treats it as a single argument.

Explanation

W#Sb&[email protected] KXWb:b@>2.$1b
                             a, b are cmdline args; s is space; XW is `\w` (implicit)
W                            While
 #                            length of
  Sb                          suffix of b (the current word)
                              is nonzero (i.e. length of b is at least 2)
    &                        and
       @b                     first character of b
         .s                   concatenated to a space
           .                  concatenated to the following regex...
               XW              word character: \w
              K                with Kleene star operator: \w*
            C                  wrapped in a capture group: (\w*)
     a~                       matches somewhere in a (the definitions)
                             do:
                 b:            Assign to b
                   b@>2        all but the first two characters of b
                       .$1     concatenated to the contents of the regex capture group
                          b  Output the final value of b