Skip to main content

Ivan Teoh

Something personal yet public

167-exercise47.js

(Source)

1
2
3
4
5
6
7
8
function between(paragraph, firstPattern, secondPattern) {
    var start = paragraph.indexOf(firstPattern) + firstPattern.length;
    var end = paragraph.indexOf(secondPattern, start);
    return paragraph.slice(start, end);
}
document.write(between("born 15/11/2003 (mother Spot): White Fang",
  "(mother ", ")")); // "Spot"
document.write(between("bu ] boo [ bah ] gzz", "[ ", " ]")); // "bah"