Skip to main content
added 902 characters in body
Source Link
NinjaBearMonkey
  • 10.4k
  • 3
  • 38
  • 67

Retina, 50 4141 26 bytes

Thanks to Martin Ender for saving 15(!) bytes.

M&M&!r`.+ O`\G..+¶ s`(.*)¶.¶(Om`^.*) $2¶$1 ¶¶[^·]+|.$+ A1` 

Trailing newline significant. Takes input with the two strings separated by a newline:

Test Testing 

Try it online!Try it online!

Explanation

M&!r`.+ 

The first line generates the "steps" of both words:

Testing Testin Testi Test Tes Te T Test Tes Te T 

M is for match mode, & considers overlapping matches, and ! prints the matches instead of the number of them. The reason it's reversed is the right-to-left option: the engine starts looking for matches at the end of the string and continues toward the beginning.

Om`^.¶[^·]+|.+ 

This gets everything in the right order: it sOrts all matches of the subsequent regex: A character on its own line and every character (including newlines) after it, which matches the whole second half as one chunk, or otherwise a line of characters, which matches each individual line. These matches are then sorted by code point, so the T followed by the newline goes first, followed by the lines, ascending by length.

A1` 

Now we just have that first character line on top so we use Antigrep mode to discard the first match of the default regex .+.

Old version

M&!r`.+ O`\G..+¶ s`(.*)¶.¶(.*) $2¶$1 ¶.$ 

Try this version online!

Explanation

The first line is the same, so see the explanation for that above.

O`\G..+¶ 

This reverses the lines of the first half (second input word). It actually sOrts the lines, and the regex limits the matches: it must be a line of two or more characters (..+) followed by a newline () that begins where the last one left off (\G). In the above example, the single T in the middle doesn't match, so nothing after it can.

Te Tes Test Testi Testin Testing T Test Tes Te T 

Now we have the right two components, but in the wrong order.

s`(.*)¶.¶(.*) $2¶$1 

¶.¶ matches the lone T in the middle, which we don't need but separates the two parts. The two (.*) capture everything before and after, including newlines thanks to single-line mode. The two captures are substituted in the right order with a newline in between.

Now we're done, unless the input strings are one character long, in which case the input hasn't changed. To get rid of the duplicate, we replace ¶.$ (when the last line of the string a single character) with nothing.

Retina, 50 41 bytes

M&!r`.+ O`\G..+¶ s`(.*)¶.¶(.*) $2¶$1 ¶.$ 

Trailing newline significant. Takes input with the two strings separated by a newline:

Test Testing 

Try it online!

Explanation

M&!r`.+ 

The first line generates the "steps" of both words:

Testing Testin Testi Test Tes Te T Test Tes Te T 

M is for match mode, & considers overlapping matches, and ! prints the matches instead of the number of them. The reason it's reversed is the right-to-left option: the engine starts looking for matches at the end of the string and continues toward the beginning.

O`\G..+¶ 

This reverses the lines of the first half (second input word). It actually sOrts the lines, and the regex limits the matches: it must be a line of two or more characters (..+) followed by a newline () that begins where the last one left off (\G). In the above example, the single T in the middle doesn't match, so nothing after it can.

Te Tes Test Testi Testin Testing T Test Tes Te T 

Now we have the right two components, but in the wrong order.

s`(.*)¶.¶(.*) $2¶$1 

¶.¶ matches the lone T in the middle, which we don't need but separates the two parts. The two (.*) capture everything before and after, including newlines thanks to single-line mode. The two captures are substituted in the right order with a newline in between.

Now we're done, unless the input strings are one character long, in which case the input hasn't changed. To get rid of the duplicate, we replace ¶.$ (when the last line of the string a single character) with nothing.

Retina, 50 41 26 bytes

Thanks to Martin Ender for saving 15(!) bytes.

M&!r`.+ Om`^.¶[^·]+|.+ A1` 

Takes input with the two strings separated by a newline:

Test Testing 

Try it online!

Explanation

M&!r`.+ 

The first line generates the "steps" of both words:

Testing Testin Testi Test Tes Te T Test Tes Te T 

M is for match mode, & considers overlapping matches, and ! prints the matches instead of the number of them. The reason it's reversed is the right-to-left option: the engine starts looking for matches at the end of the string and continues toward the beginning.

Om`^.¶[^·]+|.+ 

This gets everything in the right order: it sOrts all matches of the subsequent regex: A character on its own line and every character (including newlines) after it, which matches the whole second half as one chunk, or otherwise a line of characters, which matches each individual line. These matches are then sorted by code point, so the T followed by the newline goes first, followed by the lines, ascending by length.

A1` 

Now we just have that first character line on top so we use Antigrep mode to discard the first match of the default regex .+.

Old version

M&!r`.+ O`\G..+¶ s`(.*)¶.¶(.*) $2¶$1 ¶.$ 

Try this version online!

Explanation

The first line is the same, so see the explanation for that above.

O`\G..+¶ 

This reverses the lines of the first half (second input word). It actually sOrts the lines, and the regex limits the matches: it must be a line of two or more characters (..+) followed by a newline () that begins where the last one left off (\G). In the above example, the single T in the middle doesn't match, so nothing after it can.

Te Tes Test Testi Testin Testing T Test Tes Te T 

Now we have the right two components, but in the wrong order.

s`(.*)¶.¶(.*) $2¶$1 

¶.¶ matches the lone T in the middle, which we don't need but separates the two parts. The two (.*) capture everything before and after, including newlines thanks to single-line mode. The two captures are substituted in the right order with a newline in between.

Now we're done, unless the input strings are one character long, in which case the input hasn't changed. To get rid of the duplicate, we replace ¶.$ (when the last line of the string a single character) with nothing.

added 1509 characters in body
Source Link
NinjaBearMonkey
  • 10.4k
  • 3
  • 38
  • 67

Retina, 50 4241 bytes

M&!r`.+ O`\G..+\n s`(.*)¶.¶(.*) $2¶$1 ¶.$ 

Trailing newline significant. Takes input with the two strings separated by a newline:

Test Testing 

Try it online!

Explanation

M&!r`.+ 

The first line generates the "steps" of both words:

Testing Testin Testi Test Tes Te T Test Tes Te T 

M is for match mode, & considers overlapping matches, and ! prints the matches instead of the number of them. The reason it's reversed is the Try it online!right-to-left option: the engine starts looking for matches at the end of the string and continues toward the beginning.

O`\G..+¶ 

Explanation coming when I finish golfingThis reverses the lines of the first half (second input word). It actually sOrts the lines, and the regex limits the matches: it must be a line of two or more characters (..+) followed by a newline () that begins where the last one left off (\G). In the above example, the single T in the middle doesn't match, so nothing after it can.

Te Tes Test Testi Testin Testing T Test Tes Te T 

Now we have the right two components, but in the wrong order.

s`(.*)¶.¶(.*) $2¶$1 

¶.¶ matches the lone T in the middle, which we don't need but separates the two parts. The two (.*) capture everything before and after, including newlines thanks to single-line mode. The two captures are substituted in the right order with a newline in between.

Now we're done, unless the input strings are one character long, in which case the input hasn't changed. To get rid of the duplicate, we replace ¶.$ (when the last line of the string a single character) with nothing.

Retina, 50 42 bytes

M&!r`.+ O`\G..+\n s`(.*)¶.¶(.*) $2¶$1 ¶.$ 

Trailing newline significant. Takes input with the two strings separated by a newline. Try it online!

Explanation coming when I finish golfing.

Retina, 50 41 bytes

M&!r`.+ O`\G.. s`(.*)¶.¶(.*) $2¶$1 ¶.$ 

Trailing newline significant. Takes input with the two strings separated by a newline:

Test Testing 

Try it online!

Explanation

M&!r`.+ 

The first line generates the "steps" of both words:

Testing Testin Testi Test Tes Te T Test Tes Te T 

M is for match mode, & considers overlapping matches, and ! prints the matches instead of the number of them. The reason it's reversed is the right-to-left option: the engine starts looking for matches at the end of the string and continues toward the beginning.

O`\G..+¶ 

This reverses the lines of the first half (second input word). It actually sOrts the lines, and the regex limits the matches: it must be a line of two or more characters (..+) followed by a newline () that begins where the last one left off (\G). In the above example, the single T in the middle doesn't match, so nothing after it can.

Te Tes Test Testi Testin Testing T Test Tes Te T 

Now we have the right two components, but in the wrong order.

s`(.*)¶.¶(.*) $2¶$1 

¶.¶ matches the lone T in the middle, which we don't need but separates the two parts. The two (.*) capture everything before and after, including newlines thanks to single-line mode. The two captures are substituted in the right order with a newline in between.

Now we're done, unless the input strings are one character long, in which case the input hasn't changed. To get rid of the duplicate, we replace ¶.$ (when the last line of the string a single character) with nothing.

deleted 11 characters in body
Source Link
NinjaBearMonkey
  • 10.4k
  • 3
  • 38
  • 67

Retina, 5050 42 bytes

M&!r`.+ O`O`\G.+(?=(?s).*¶.¶)+\n s`(.*)¶.¶(.*) $2¶$1 ¶.$ 

Trailing newline significant. Takes input with the two strings separated by a newline. Try it online!Try it online!

Explanation coming when I finish golfing.

Retina, 50 bytes

M&!r`.+ O`.+(?=(?s).*¶.¶) s`(.*)¶.¶(.*) $2¶$1 ¶.$ 

Trailing newline significant. Takes input with the two strings separated by a newline. Try it online!

Explanation coming when I finish golfing.

Retina, 50 42 bytes

M&!r`.+ O`\G..+\n s`(.*)¶.¶(.*) $2¶$1 ¶.$ 

Trailing newline significant. Takes input with the two strings separated by a newline. Try it online!

Explanation coming when I finish golfing.

Source Link
NinjaBearMonkey
  • 10.4k
  • 3
  • 38
  • 67
Loading