Return The String Between The Start And End - Node.js String

Node.js examples for String:Search

Description

Return The String Between The Start And End

Demo Code


/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


//IF end IS UNDEFINED, THEN GRABS TO END OF STRING
String.prototype.between=function(start, end){
  var s=this.indexOf(start);
  if (s==-1) return null;
  s+=start.length;//www.j ava 2  s. c  o m
  if (end===undefined) return this.substring(s);

  var e=this.indexOf(end, s);
  if (e==-1) return null;
  return this.substring(s, e);
};

Related Tutorials