Created
May 17, 2019 23:36
-
-
Save mkdizajn/18dad60381a94c015d9819276ef6b74f to your computer and use it in GitHub Desktop.
JavaScript multiline search for string in string with delimiters or markers. Uses regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var start = "some starting term"; | |
var end = "some ending term"; | |
var reg = new RegExp("(?:"+ start +")([\\s\\S]*)(?:"+ end +")", "igm"); | |
var j = res.match( reg ); | |
// example with search markers | |
var txt = `Lorem Ipsum is simply dummy | |
text of the printing and typesetting industry. | |
Lorem Ipsum has been the industry's standard | |
dummy text ever since the 1500s, when an unknown printer | |
took a galley of type and scrambled it to make | |
a type specimen book.`; | |
var start = 'Ipsum' | |
var end = 'dummy' | |
var reg = new RegExp("(?:"+ start +")([\\s\\S]*)(?:"+ end +")", "igm"); | |
var j = txt.match( reg ); | |
console.log(j) | |
// ["Ipsum is simply dummy ↵text of the printing and ty…rem Ipsum has been the industry's standard ↵dummy"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment