|text to get| Other text.... migh have \"|\"\'s ...
How can I get the text to get
stuff from the string (and remove it)?
It should
You don't need a regular expression for this; firing up the regex engine is completely overkill for such a simple task.
Just use basic string manipulation:
function getSubStr(str, delim) {
var a = str.indexOf(delim);
if (a == -1)
return '';
var b = str.indexOf(delim, a+1);
if (b == -1)
return '';
return str.substr(a+1, b-a-1);
// ^ ^- length = gap between delimiters
// |- start = just after the first delimiter
}
print(getSubStr('|text to get| Other text.... migh have "|"s ...', '|'));
// Output: text to get