@@ -175,7 +175,7 @@ export function substringAfter(value: string, delimiter: string | RegExp): strin
175
175
}
176
176
177
177
/**
178
- * Get the substring between the first occurrence of the specified start and end string.
178
+ * Get the substring between the last occurrence of the specified start and end string.
179
179
* If the end string is not found the substring after the start string is returned.
180
180
* If the start string is not found but the end of the string is found the substring before the end string is returned.
181
181
* @param value value to search in
@@ -196,6 +196,27 @@ export function substringBetweenLast(value: string, start: string, end: string):
196
196
return value ;
197
197
}
198
198
199
+ /**
200
+ * Returns the first occurrence of the substring between the specified start and end needles.
201
+ * If the start needle is not found, returns the original string.
202
+ * If the end needle is not found, returns the substring from after the start needle to the end of the string.
203
+ * @param value Input string
204
+ * @param start The starting needle
205
+ * @param end The ending needle
206
+ */
207
+ export function substringBetween ( value : string , start : string , end : string ) : string {
208
+ const startIndex = value . indexOf ( start ) ;
209
+ if ( startIndex === - 1 ) {
210
+ return value ;
211
+ }
212
+ const startPos = startIndex + start . length ;
213
+ const endIndex = value . indexOf ( end , startPos ) ;
214
+ if ( endIndex === - 1 ) {
215
+ return value . substring ( startPos ) ;
216
+ }
217
+ return value . substring ( startPos , endIndex ) ;
218
+ }
219
+
199
220
/**
200
221
* Joins array parts together in one or more strings based on the max size of the string
201
222
* @param parts
0 commit comments