We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e82e1c3 commit c3d4c22Copy full SHA for c3d4c22
src/string/split_between_tokens.ts
@@ -0,0 +1,22 @@
1
+import { isEmpty } from '../array/mod.ts';
2
+
3
+/**
4
+ * This function spits a string between tokens.
5
+ *
6
+ * @param input The input string
7
+ * @param tokens A list of char tokens
8
+ * @returns The spited array
9
+ */
10
+export default function splitBetweenTokens(
11
+ input : string,
12
+ tokens : string[]
13
+) : string[] {
14
+ if (!input) {
15
+ return [];
16
+ }
17
+ if (isEmpty(tokens)) {
18
+ return [input];
19
20
+ const escapedTokens = `\\${tokens.join('\\')}`;
21
+ return input.split(new RegExp(`(?=[${escapedTokens}])|(?<=[${escapedTokens}]+)`));
22
+}
0 commit comments