JSFiddle - React, Tailwind, and code Playground
HTML
<title>String to CamelCase convertor</title>
<body>
<input type="text" placeholder="type a string, eg: chetan-Ankola###.com---m13ok#-#alo" id='input' style="width:400px; height:30px; font-size:13px;" />
<p id="output" style="font-size:13px;">Regex output, type something in searchbox</p>
<script>
</script>
</body>
JavaScript
var output = document.getElementById("output");
var box = document.getElementById("input");
//var regex = 'chetan-Ankola###.com---m13ok#-#alo(*finding!R%S#%-GFF';
var camelCaser = function (str) {
// Where [-_ .] is the seperator, you can add say '@' too
// + is to handle repetition of seperator
// ? is to take care of preceeding token
// match nov(ember)? matches nov and november
var camelCased = str.replace(/[-_ .]+(.)?/g, function (match, p) {
if (p) {
return p.toUpperCase();
}
return '';
}).replace(/[^\w]/gi, ''); //strip unwanted characters
return camelCased;
};
box.onkeyup = function (e) {
output.innerHTML = camelCaser(this.value);
}