I have a simple code that is separating book title from serial using the ":" as separator. This is really a straight forward solution and should work. On my website it's working but stopping when using german umlauts in the book title. So I created a JSFiddle to find out what's going on but the code breaks whenever I'm using the replace() function.
html:
<div id="title">Die Träne des Fressers: Weiße Königin</div>
Title:<div id="output_title">output title</div>
Serial:<div id="output_serial">output serial</div>
js:
title_input = $("#title").text();
title = title_input.match(/[a-z\s,äöüß-]*.*:/i);
serial = title_input.match(/:\s?[a-z\s,äöüß-]*/i);
title.replace(/\:/g,'');
//serial = serial.replace(/[:|\.]+/g, "").trim();
$("#output_title").text(title);
$("#output_serial").text(serial);
I do not understand what's going on. Could someone explain it to me?
.replace()method returns a new string. It does not change the original string..match()function always returns an array, not a string. The first element of the array (element 0) will contain the matched substring.