diff --git a/index-of-match-end.js b/index-of-match-end.js new file mode 100644 index 0000000..6180e53 --- /dev/null +++ b/index-of-match-end.js @@ -0,0 +1,8 @@ +function indexOfMatchEnd(xml, pattern, startIndex) { + const re = new RegExp(pattern); + const match = re.exec(xml.slice(startIndex)); + if (match) return startIndex + match.index + match[0].length - 1; + else return -1; +} + +module.exports = indexOfMatchEnd; diff --git a/package.json b/package.json index 552f31d..fe90376 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "find-tags-by-path.js", "get-attribute.js", "index-of-match.js", + "index-of-match-end.js", "index.js" ], "scripts": {