diff --git a/core/.eslintrc.json b/core/.eslintrc.json
index 87a132cf995f6cc35a9697242bb00f81bbab0bc4..6a6916b1a2c0aef4d1f49b21c18bf21c423f067b 100644
--- a/core/.eslintrc.json
+++ b/core/.eslintrc.json
@@ -27,7 +27,7 @@
     "once": true,
     "CKEditor5": true,
     "tabbable": true,
-    "slugify": true,
+    "transliterate": true,
     "bodyScrollLock" : true,
     "FloatingUIDOM": true
   },
diff --git a/core/misc/machine-name.js b/core/misc/machine-name.js
index 28f1b39ddf49863e760dd7443391cbf2d92b15fe..fab22fae8286bb7e16330c0794a539ce2533eff9 100644
--- a/core/misc/machine-name.js
+++ b/core/misc/machine-name.js
@@ -5,7 +5,7 @@
  * @internal
  */
 
-(function ($, Drupal, drupalSettings, slugify) {
+(function ($, Drupal, drupalSettings, transliterateLibrary) {
   /**
    * Trims string by a character.
    *
@@ -294,21 +294,17 @@
         drupalSettings.transliteration_language_overrides[
           drupalSettings.langcode
         ];
-      const normalizedLanguageOverrides = {};
+      const replace = {};
       if (languageOverrides) {
         Object.keys(languageOverrides).forEach((key) => {
           // Updates the keys from hexadecimal to strings.
-          normalizedLanguageOverrides[String.fromCharCode(key)] =
-            languageOverrides[key];
+          replace[String.fromCharCode(key)] = languageOverrides[key];
         });
       }
-      slugify.config({
-        separator: settings.replace,
-        allowedChars: settings.replace_pattern,
-        replace: normalizedLanguageOverrides,
-      });
 
-      return prepareMachineName(slugify(source), settings);
+      const transliteratedSource = transliterateLibrary(source, { replace });
+
+      return prepareMachineName(transliteratedSource, settings);
     },
   };
-})(jQuery, Drupal, drupalSettings, slugify);
+})(jQuery, Drupal, drupalSettings, transliterate);
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/MachineName/MachineNameTransliterationTest.php b/core/tests/Drupal/FunctionalJavascriptTests/MachineName/MachineNameTransliterationTest.php
index 9cb079d954d78317c56e024fba8c9bd61cdb8881..f1d516635e4cfea866901ebf8296588137ba5ca8 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/MachineName/MachineNameTransliterationTest.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/MachineName/MachineNameTransliterationTest.php
@@ -61,8 +61,7 @@ public function testMachineNameTransliterations($langcode, $input, $output): voi
 
     $this->drupalGet("/admin/people/roles/add");
     $page->find('css', '[data-drupal-selector="edit-label"]')->setValue($input);
-    $this->assertSession()->pageTextContains($output);
-
+    $this->assertSession()->elementTextEquals('css', 'span.machine-name-value', $output);
   }
 
   /**
@@ -78,13 +77,13 @@ public static function machineNameInputOutput(): array {
       ['de', 'Äwesome', 'aewesome'],
       ['da', 'äöüåøhello', 'aouaaoehello'],
       ['fr', 'ц', 'c'],
-      // These tests are not working with chromedriver as
-      // 'ᐑ','𐌰𐌸' chars are not accepted.
-      // ['fr', 'ᐑ', 'wii'],
+      ['fr', 'ᐑ', 'wii'],
+      // This test is not working with chromedriver as '𐌰𐌸' chars are not
+      // accepted.
       // ['en', '𐌰𐌸', '__'],
       ['en', 'Ä Ö Ü Å Ø äöüåøhello', 'a_o_u_a_o_aouaohello'],
       ['de', 'Ä Ö Ü Å Ø äöüåøhello', 'ae_oe_ue_a_o_aeoeueaohello'],
-      ['de', ']URY&m_G^;', ' ury_m_g'],
+      ['de', ']URY&m_G^;', 'ury_m_g'],
       ['da', 'Ä Ö Ü Å Ø äöüåøhello', 'a_o_u_aa_oe_aouaaoehello'],
       ['kg', 'ц', 'ts'],
       ['en', ' Hello Abventor! ', 'hello_abventor'],
diff --git a/core/tests/Drupal/Nightwatch/Tests/machineNameTransliterationTest.js b/core/tests/Drupal/Nightwatch/Tests/machineNameTransliterationTest.js
index 9241e7973daf313e8e1206e0ebf2e38d4bcbed24..635ce5f6f82e9e5d875ed101e71fb297b0cd5da6 100644
--- a/core/tests/Drupal/Nightwatch/Tests/machineNameTransliterationTest.js
+++ b/core/tests/Drupal/Nightwatch/Tests/machineNameTransliterationTest.js
@@ -2,42 +2,42 @@
 const MachineNameTestArray = [
   {
     machineName: 'Bob',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'bob',
   },
   {
     machineName: 'Äwesome',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'awesome',
   },
   {
     machineName: 'B?!"@\\/-ob@e',
-    replacePattern: 'a-zA-Z0-9_.~',
+    replacePattern: '[^a-zA-Z0-9_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'b_ob_e',
   },
   {
     machineName: 'Bob@e\\0',
-    replacePattern: 'a-zA-Z0-9_.~@',
+    replacePattern: '[^a-zA-Z0-9_.~@]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'bob@e_0',
   },
   {
     machineName: 'Bobby',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'bobby',
   },
   {
     machineName: 'ǍǎǏ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'aai',
@@ -46,140 +46,140 @@ const MachineNameTestArray = [
   // the removeDiacritics() function present in PhpTranliteration.php.
   {
     machineName: 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'aaaaaaaeceeeeiiii',
   },
   {
     machineName: 'ÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'dnoooooxouuuuuthss',
   },
   {
     machineName: 'àáâãäåæçèéêëìíîï',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'aaaaaaaeceeeeiiii',
   },
   {
     machineName: 'ðñòóôõö÷øùúûüýþÿ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'dnooooo_ouuuuythy',
   },
   {
     machineName: 'ĀāĂ㥹ĆćĈĉĊċČčĎď',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'aaaaaaccccccccdd',
   },
   {
     machineName: 'ĐđĒēĔĕĖėĘęĚěĜĝĞğ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'ddeeeeeeeeeegggg',
   },
   {
     machineName: 'ĠġĢģĤĥĦħĨĩĪīĬĭĮį',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'gggghhhhiiiiiiii',
   },
   {
     machineName: 'İıIJijĴĵĶķĸĹĺĻļĽľĿ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'iiijijjjkkklllllll',
   },
   {
     machineName: 'ŀŁłŃńŅņŇňʼnŊŋŌōŎŏ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'lllnnnnnn_nngngoooo',
   },
   {
     machineName: 'ŐőŒœŔŕŖŗŘřŚśŜŝŞş',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'oooeoerrrrrrssssss',
   },
   {
     machineName: 'ŠšŢţŤťŦŧŨũŪūŬŭŮů',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'ssttttttuuuuuuuu',
   },
   {
     machineName: 'ŰűŲųŴŵŶŷŸŹźŻżŽž',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'uuuuwwyyyzzzzzz',
   },
   {
     machineName: 'ǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'ioouuuuuuuuuu_aa',
   },
   {
     machineName: 'ǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'aaaeaeggggkkoooozhzh',
   },
   {
     machineName: 'ǰDZDzdzǴǵǶǷǸǹǺǻǼǽǾǿ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'jdzddzgghvwnnaaaeaeoo',
   },
   {
     machineName: 'ȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'aaaaeeeeiiiioooo',
   },
   {
     machineName: 'ȐȑȒȓȔȕȖȗȘșȚțȜȝȞȟ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'rrrruuuussttyyhh',
   },
   {
     machineName: 'ȠȡȢȣȤȥȦȧȨȩȪȫȬȭȮȯ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'ndououzzaaeeoooooo',
   },
   {
     machineName: 'ȰȱȲȳȴȵȶȷȸȹȺȻȼȽȾȿ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'ooyylntjdbqpacclts',
   },
   {
     machineName: 'ɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏ',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 64,
     expectedMachineName: 'z_buveejjqqrryy',
@@ -187,25 +187,39 @@ const MachineNameTestArray = [
   // Test for maximum length of machine-name
   {
     machineName: 'This is the test for max length',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 20,
     expectedMachineName: 'this_is_the_test_for',
   },
   {
     machineName: 'Ma@Chi!~',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '_',
     maxlength: 5,
     expectedMachineName: 'ma_ch',
   },
   {
     machineName: 'Test for custom replace character',
-    replacePattern: 'a-zA-Z0-9-_.~',
+    replacePattern: '[^a-zA-Z0-9-_.~]+',
     replaceChar: '-',
     maxlength: 64,
     expectedMachineName: 'test-for-custom-replace-character',
   },
+  {
+    machineName: 'Test for unusual replace pattern',
+    replacePattern: '([^a-z0-9_]+)|(^custom$)',
+    replaceChar: '_',
+    maxlength: 64,
+    expectedMachineName: 'test_for_unusual_replace_pattern',
+  },
+  {
+    machineName: 'custom',
+    replacePattern: '([^a-z0-9_]+)|(^custom$)',
+    replaceChar: '_',
+    maxlength: 64,
+    expectedMachineName: '_',
+  },
   // cSpell:enable
 ];
 module.exports = {