I’m trying to split a multiline string using a regex.
const regexCommitSha = RegExp(/([0-9a-f]{7})s/m)
const result = commits.split(regexCommitSha)
console.log(result)
This is my multiline string (commits
):
1234567 fix: simple bug fix
apps/backend/src/lib/file.ts
1234567 fix: second bug fix
apps/backend/src/lib/file.ts
apps/frontend/src/lib/file.ts
1234567 feat: new feature
apps/frontend/src/lib/file.ts
1234567 feat: second feature
apps/frontend/src/lib/file.ts
And this is my result:
[
'',
'1234567',
'fix: simple bug fixnapps/backend/src/lib/file.tsn',
'1234567',
'fix: second bug fixn' +
'apps/backend/src/lib/file.tsn' +
'apps/frontend/src/lib/file.tsn',
'1234567',
'feat: new featurenapps/frontend/src/lib/file.tsn',
'1234567',
'feat: second featurenapps/frontend/src/lib/file.ts'
]
Why do I have the empty string as first element and why do I have '1234567'
-elements in my result array? As this is my splitter, I thought this is not existing in the result.
I would expect
[
'fix: simple bug fixnapps/backend/src/lib/file.tsn',
'fix: second bug fixn' +
'apps/backend/src/lib/file.tsn' +
'apps/frontend/src/lib/file.tsn',
'feat: new featurenapps/frontend/src/lib/file.tsn',
'feat: second featurenapps/frontend/src/lib/file.ts'
]
What am I doing wrong?