i need your help with a regex in javascript.
I've got an a-tag with follow pattern
<a href='#'>
<!--:de-->some german text<!--:--><!--:en-->some english text<!--:-->
</a>
So, now i'm searching for a regular expression what extract me each part
1. <!--:de-->some german text<!--:-->
2. <!--:en-->some german text<!--:-->
Thanks VERY much in advance
Try this:
var str = '<!--:de-->some german text<!--:--><!--:en-->some english text<!--:-->';
var match = str.match(/de-->([^<]+).+?en[^>]+>([^<]+)/i);
var textInDe = match[1];
var textInEn = match[2];
Try this Javascript code:
var ger = /<!--:de-->.*?<!--:-->/g;
document.writeln(html.match(ger).map(function (s) { return s; }));
var eng = /<!--:en-->.*?<!--:-->/g;
document.writeln(html.match(eng).map(function (s) { return s; }));
some german text
some english text
If you are expecting more than 2 parts, i would recommend you split the string by the delimiter
var str="<!--:de-->some german text<!--:--><!--:en-->some english text<!--:--><!--:fr-->some french text<!--:-->";
var col_array=str.split("<!--:-->");
var part_num=0;
while (part_num < col_array.length)
{
document.write(col_array[part_num]+"<br>");
part_num+=1;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With