I have got this javascript string:


And I have to parse it to obtain every "language" in distinct strings. The perfect is always to possess a function like:

function getText(text, lang){
    // get and return the string of the language "lang" inside the multilang string "text"

Will be able to call like this:

var frenchText = getText("<!--:fr-->Photos<!--:--><!--:en-->Pictures<!--:-->","fr");
// and would return:
// frenchText = Photos

If anybody know a great way to do this, most likely having a regexp that might be FANTASTIC!!!

I do not think much explanation is essential you simply add lang to some template for the regex and obtain the very first backref (the (.*?) part). I do not believe any kind of the provided string comprises a reserved character. Note you could include some error handling just in case no match is located, but I'll leave that towards the OP:

function getText(text, lang) {
  // Builds regex based on supplied language
  var re = new RegExp("<!--:" + lang + "-->(.*?)<!--:-->");

  // Returns first backreference
  return text.match(re)[1];
getText("<!--:fr-->Photos<!--:--><!--:en-->Pictures<!--:-->", "fr");
// returns "Photos"