Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

removed golf to prefix/suffix code as it was too slow
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Retina 0.8.2, (削除) 7576 (削除ここまで) 5758 bytes

^(.*)(.*?)1円
2ドル
(.*)¶1円(.*)3円$1円$
2ドル¶4ドル2ドル
^.?¶.?$
^.?(.*).?¶.?1円.?$

Try it online! Try it online! Takes the two strings on separate lines, but link includes test suite which takes space-separated strings instead, so that I can easily use the test cases. Explanation:

^(.*)(.*?)1円
2ドル

Delete the common prefix.

(.*)¶1円(.*)3円$1円$
2ドル¶4ドル2ドル

Delete the common prefix and suffix.

^.?¶.?$

Ignore an edit distance of less than two.

^.?(.*).?¶.?1円.?$

Check that only the first and last characters have been edited, so that the edit distance cannot be greater than two in this case.

From a code golf point of view this can be done in 51 bytes but then the regex becomes unbearably slow to execute for longer strings:

^(?!(.*).?(.*)¶1円.?2円$)(.*).?(.*).?(.*)¶3円.?4円.?5円$

Try it online! Takes the two strings on separate lines, but link includes test suite which takes space-separated strings instead, so that I can easily use the test cases. Explanation:

^

Match the whole input.

(?!(.*).?(.*)¶1円.?2円$)

Don't match strings with an edit distance less than two.

(.*).?(.*).?(.*)¶3円.?4円.?5円$

Match strings with an edit distance less than three.

Retina 0.8.2, (削除) 75 (削除ここまで) 57 bytes

^(.*)(.*?)(.*)¶1円(.*)3円$
2ドル¶4ドル
^.?¶.?$
^.?(.*).?¶.?1円.?$

Try it online! Takes the two strings on separate lines, but link includes test suite which takes space-separated strings instead, so that I can easily use the test cases. Explanation:

^(.*)(.*?)(.*)¶1円(.*)3円$
2ドル¶4ドル

Delete the common prefix and suffix.

^.?¶.?$

Ignore an edit distance of less than two.

^.?(.*).?¶.?1円.?$

Check that only the first and last characters have been edited, so that the edit distance cannot be greater than two in this case.

Retina 0.8.2, (削除) 76 (削除ここまで) 58 bytes

^(.*)(.)1円
2ドル
(.*)(.*)1円$
2ドル
^.?¶.?$
^.?(.*).?¶.?1円.?$

Try it online! Takes the two strings on separate lines, but link includes test suite which takes space-separated strings instead, so that I can easily use the test cases. Explanation:

^(.*)(.)1円
2ドル

Delete the common prefix.

(.*)(.*)1円$
2ドル

Delete the common suffix.

^.?¶.?$

Ignore an edit distance of less than two.

^.?(.*).?¶.?1円.?$

Check that only the first and last characters have been edited, so that the edit distance cannot be greater than two in this case.

From a code golf point of view this can be done in 51 bytes but then the regex becomes unbearably slow to execute for longer strings:

^(?!(.*).?(.*)¶1円.?2円$)(.*).?(.*).?(.*)¶3円.?4円.?5円$

Try it online! Takes the two strings on separate lines, but link includes test suite which takes space-separated strings instead, so that I can easily use the test cases. Explanation:

^

Match the whole input.

(?!(.*).?(.*)¶1円.?2円$)

Don't match strings with an edit distance less than two.

(.*).?(.*).?(.*)¶3円.?4円.?5円$

Match strings with an edit distance less than three.

deleted 86 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Retina 0.8.2, 75(削除) 75 (削除ここまで) 57 bytes

^(.*)(.*?)(.*)¶1円(.*)3円$
2ドル¶4ドル
^.?¶.?$
^(.)?(.*)(.)(?(1).?|.)2円(?(3)1円.?|.)$

Try it online! Try it online! Takes the two stringstrings on separate lines, but link includes test suite which takes space-separated strings instead, so that I can easily use the test cases. Explanation:

^(.*)(.*?)(.*)¶1円(.*)3円$
2ドル¶4ドル

Delete the common prefix and suffix.

^.?¶.?$

Ignore a single-character edit, as the next test will "expand" it into a insert plus a delete, erroneously allowing it to be an edit distance of less than two.

^(.)?(.*)(.)(?(1).?|.)2円(?(3)1円.?|.)$

Check that only the first and last characters have been edited, so that the edit distance cannot be greater than two in this case.

Retina 0.8.2, 75 bytes

^(.*)(.*?)(.*)¶1円(.*)3円$
2ドル¶4ドル
^.¶.$
^(.)?(.*)(.)(?(1).?|.)2円(?(3).?|.)$

Try it online! Takes the two string on separate lines, but link includes test suite which takes space-separated strings instead, so that I can easily use the test cases. Explanation:

^(.*)(.*?)(.*)¶1円(.*)3円$
2ドル¶4ドル

Delete the common prefix and suffix.

^.¶.$

Ignore a single-character edit, as the next test will "expand" it into a insert plus a delete, erroneously allowing it to be an edit distance of two.

^(.)?(.*)(.)(?(1).?|.)2円(?(3).?|.)$

Check that only the first and last characters have been edited.

Retina 0.8.2, (削除) 75 (削除ここまで) 57 bytes

^(.*)(.*?)(.*)¶1円(.*)3円$
2ドル¶4ドル
^.?¶.?$
^.?(.*).?¶.?1円.?$

Try it online! Takes the two strings on separate lines, but link includes test suite which takes space-separated strings instead, so that I can easily use the test cases. Explanation:

^(.*)(.*?)(.*)¶1円(.*)3円$
2ドル¶4ドル

Delete the common prefix and suffix.

^.?¶.?$

Ignore an edit distance of less than two.

^.?(.*).?¶.?1円.?$

Check that only the first and last characters have been edited, so that the edit distance cannot be greater than two in this case.

Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Retina 0.8.2, 75 bytes

^(.*)(.*?)(.*)¶1円(.*)3円$
2ドル¶4ドル
^.¶.$
^(.)?(.*)(.)?¶(?(1).?|.)2円(?(3).?|.)$

Try it online! Takes the two string on separate lines, but link includes test suite which takes space-separated strings instead, so that I can easily use the test cases. Explanation:

^(.*)(.*?)(.*)¶1円(.*)3円$
2ドル¶4ドル

Delete the common prefix and suffix.

^.¶.$

Ignore a single-character edit, as the next test will "expand" it into a insert plus a delete, erroneously allowing it to be an edit distance of two.

^(.)?(.*)(.)?¶(?(1).?|.)2円(?(3).?|.)$

Check that only the first and last characters have been edited.

AltStyle によって変換されたページ (->オリジナル) /