Skip to content

Instantly share code, notes, and snippets.

@mkdizajn
Created May 17, 2019 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkdizajn/18dad60381a94c015d9819276ef6b74f to your computer and use it in GitHub Desktop.
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
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