Here i split it up, and filter it.
Keep in mind this wont work in IE, you will need an Polyfill
let bigString = "apples1h7s5e47epears hrrdjhrdjdrj apples15r4h775h47pears hrmbaewv4kg0k apples15hrs477sr547pears";
let result = bigString.split(" ").filter(el => el.startsWith("apples") && el.endsWith("pears"))
console.log(result);
startsWith
Polyfill:
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position) {
position = position || 0;
return this.indexOf(searchString, position) === position;
};
}
endsWith
Polyfill:
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(searchString, position) {
var subjectString = this.toString();
if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
position = subjectString.length;
}
position -= searchString.length;
var lastIndex = subjectString.indexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
};
}