Skip to main content
new extra option rules
Source Link
mik
  • 500
  • 3
  • 11

Perl 5, 44 (code) + 1 (-p) = 45, 44 bytes

1while s,(/)\|(?!\\)|(?<!/)\|(\\),$1$1$2$2,g

Try it online!

Explanation

1while s,                        ,        ,g   while anything found substitute globally
         (/)\|(?!\\)              $1$1         /| that is not followed by \ to //
                    |                          or
                     (?<!/)\|(\\)     $2$2     |\ that is not preceded by / to \\

Perl 5, 44 (code) + 1 (-p) = 45 bytes

1while s,(/)\|(?!\\)|(?<!/)\|(\\),$1$1$2$2,g

Try it online!

Explanation

1while s,                        ,        ,g   while anything found substitute globally
         (/)\|(?!\\)              $1$1         /| that is not followed by \ to //
                    |                          or
                     (?<!/)\|(\\)     $2$2     |\ that is not preceded by / to \\

Perl 5 -p, 44 bytes

1while s,(/)\|(?!\\)|(?<!/)\|(\\),$1$1$2$2,g

Try it online!

Explanation

1while s,                        ,        ,g   while anything found substitute globally
         (/)\|(?!\\)              $1$1         /| that is not followed by \ to //
                    |                          or
                     (?<!/)\|(\\)     $2$2     |\ that is not preceded by / to \\
Rollback to Revision 2
Source Link
mik
  • 500
  • 3
  • 11

Perl 5, 3944 (code) + 1 (-p) = 4045 bytes

1while s,(/)\|(?!\\)|(?<!/)\|(\\),$+$+$1$1$2$2,g&&redog

Try it online!Try it online!

  

Explanation

1while s,                        ,        ,g   while anything found substitute globally
       substitute
  (/)\|(?!\\)                     $1$1         /| that is not followed by \ capturingto //
             |       |                          or
                     (?<!/)\|(\\)            $2$2     |\ that is not preceded by / capturing \
                          ,$+$+,g          to what was captured repeated twice, globally
                                 &&redo    if matched then redo\\

Perl 5, 39 (code) + 1 (-p) = 40 bytes

s,(/)\|(?!\\)|(?<!/)\|(\\),$+$+,g&&redo

Try it online!

 

Explanation

s,                                         substitute
  (/)\|(?!\\)                              /| that is not followed by \ capturing /
             |                             or
              (?<!/)\|(\\)                 |\ that is not preceded by / capturing \
                          ,$+$+,g          to what was captured repeated twice, globally
                                 &&redo    if matched then redo

Perl 5, 44 (code) + 1 (-p) = 45 bytes

1while s,(/)\|(?!\\)|(?<!/)\|(\\),$1$1$2$2,g

Try it online!

 

Explanation

1while s,                        ,        ,g   while anything found substitute globally
         (/)\|(?!\\)              $1$1         /| that is not followed by \ to //
                    |                          or
                     (?<!/)\|(\\)     $2$2     |\ that is not preceded by / to \\
`redo` instead of `while`
Source Link
mik
  • 500
  • 3
  • 11

Perl 5, 4039 (code) + 1 (-p) = 4140 bytes

1while s,(/)\|(?!\\)|(?<!/)\|(\\),$+$+,gg&&redo

Try it online!Try it online!

  

Explanation

1while s,                                  while anything found substitute
       substitute
  (/)\|(?!\\)                              /| that is not followed by \ capturing /
             |       |                      or
                     (?<!/)\|(\\)                 |\ that is not preceded by / capturing \
                          ,$+$+,g       ,$+$+,g   to what was captured repeated twice, globally
                                 &&redo    if matched then redo

Perl 5, 40 (code) + 1 (-p) = 41 bytes

1while s,(/)\|(?!\\)|(?<!/)\|(\\),$+$+,g

Try it online!

 

Explanation

1while s,                                  while anything found substitute
         (/)\|(?!\\)                       /| that is not followed by \ capturing /
                    |                      or
                     (?<!/)\|(\\)          |\ that is not preceded by / capturing \
                                 ,$+$+,g   to what was captured repeated twice, globally

Perl 5, 39 (code) + 1 (-p) = 40 bytes

s,(/)\|(?!\\)|(?<!/)\|(\\),$+$+,g&&redo

Try it online!

 

Explanation

s,                                         substitute
  (/)\|(?!\\)                              /| that is not followed by \ capturing /
             |                             or
              (?<!/)\|(\\)                 |\ that is not preceded by / capturing \
                          ,$+$+,g          to what was captured repeated twice, globally
                                 &&redo    if matched then redo
use of `$+` (saved 4 bytes)
Source Link
mik
  • 500
  • 3
  • 11
Loading
added explanation
Source Link
mik
  • 500
  • 3
  • 11
Loading
Source Link
mik
  • 500
  • 3
  • 11
Loading