I whould like to replace everything between the ;#
characters with a new line (<br>
). How can i do this in JavaScript?
Example:
String:
Beilagenteller - Mixed vegetables plate;#369;#Fischfilet mit Kräutersoße - Fish fillet, herbs sauce,;#183;#Rinderroulade "Hausfrauen Art", (S) Soße - Beef olive with sauce
Result:
Beilagenteller - Mixed vegetables plate
Fischfilet mit Kräutersoße - Fish fillet, herbs sauce,
Rinderroulade "Hausfrauen Art", (S) Soße - Beef olive with sauce
I whould like to replace everything between the ;#
characters with a new line (<br>
). How can i do this in JavaScript?
Example:
String:
Beilagenteller - Mixed vegetables plate;#369;#Fischfilet mit Kräutersoße - Fish fillet, herbs sauce,;#183;#Rinderroulade "Hausfrauen Art", (S) Soße - Beef olive with sauce
Result:
Share Improve this question edited Aug 5, 2015 at 10:20 James Donnelly 129k35 gold badges215 silver badges223 bronze badges asked Aug 5, 2015 at 10:10 Nagy IstvanNagy Istvan 2023 silver badges13 bronze badges 1Beilagenteller - Mixed vegetables plate
Fischfilet mit Kräutersoße - Fish fillet, herbs sauce,
Rinderroulade "Hausfrauen Art", (S) Soße - Beef olive with sauce
- Mhhmmm... Fischfilet mit Kräutersoße - such a delicious question :) – Octav Zlatior Commented Aug 5, 2015 at 10:22
3 Answers
Reset to default 3Assuming the value between the ;#
s is always numeric, you can use the regular expression /;#\d*;#/g
within a replace()
call on the string:
var input = 'Beilagenteller - Mixed vegetables plate;#369;#Fischfilet mit Kräutersoße - Fish fillet, herbs sauce,;#183;#Rinderroulade "Hausfrauen Art", (S) Soße - Beef olive with sauce';
var output = input.replace(/;#\d*;#/g, "<br>");
document.write(output);
To show what the regular expression does, here is a visualisation:
You might want to try this:
var str = "Beilagenteller - Mixed vegetables plate;#369;#Fischfilet mit Kräutersoße - Fish fillet, herbs sauce,;#183;#Rinderroulade \"Hausfrauen Art\", (S) Soße - Beef olive with sauce";
str = str.replace(/;#[0-9]*;#/g, "<br/>");
console.log(str);
Use the folowing code
address="Beilagenteller - Mixed vegetables plate;#369;#Fischfilet mit Kräutersoße - Fish fillet, herbs sauce,;#183;#Rinderroulade 'Hausfrauen Art', (S) Soße - Beef olive with sauce"
address= str.replace(/;#[0-9]*;#/g, "\n");