JSFiddle - React, Tailwind, and code Playground
HTML
<input type="button" value="Test" id="button" />
<pre id="output"></pre>
JavaScript
$('#button').click(function() {
path = "controller/action,/param";
var result = path.replace(/[^a-zA-Z0-9_\x7f-\xff]*/g, "_");
$('#output').text(result);
});