mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'fix/regex-capture-error' into chore/all-my-stuffs
This commit is contained in:
commit
57b0978bb6
2 files changed
+51
-4
No files matched your search
@@ -92,6 +92,51 @@ const regexesData = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
regex: '\\s([^\\s\\[]+)(?:\\[(\\d+)\\])?:\\s',
|
||||
text: 'Nov 11 21:03:26 abc2 def.sh[1]: \nNov 11 21:03:26 abc2 def.sh: ',
|
||||
flags: 'gm',
|
||||
result: [
|
||||
{
|
||||
captures: [
|
||||
{
|
||||
end: 27,
|
||||
name: '1',
|
||||
start: 21,
|
||||
value: 'def.sh',
|
||||
},
|
||||
{
|
||||
end: 29,
|
||||
name: '2',
|
||||
start: 28,
|
||||
value: '1',
|
||||
},
|
||||
],
|
||||
groups: [],
|
||||
index: 20,
|
||||
value: ' def.sh[1]: ',
|
||||
},
|
||||
{
|
||||
captures: [
|
||||
{
|
||||
end: 60,
|
||||
name: '1',
|
||||
start: 54,
|
||||
value: 'def.sh',
|
||||
},
|
||||
{
|
||||
end: -1,
|
||||
name: '2',
|
||||
start: -1,
|
||||
value: undefined,
|
||||
},
|
||||
],
|
||||
groups: [],
|
||||
index: 53,
|
||||
value: ' def.sh: ',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
describe('regex-tester', () => {
|
||||
|
||||
@@ -31,21 +31,23 @@ export function matchRegex(regex: string, text: string, flags: string) {
|
||||
const captures: Array<GroupCapture> = [];
|
||||
Object.entries(match).forEach(([captureName, captureValue]) => {
|
||||
if (captureName !== '0' && captureName.match(/\d+/)) {
|
||||
const captureIndices = indices[Number(captureName)] || [-1, -1];
|
||||
captures.push({
|
||||
name: captureName,
|
||||
value: captureValue,
|
||||
start: indices[Number(captureName)][0],
|
||||
end: indices[Number(captureName)][1],
|
||||
start: captureIndices[0],
|
||||
end: captureIndices[1],
|
||||
});
|
||||
}
|
||||
});
|
||||
const groups: Array<GroupCapture> = [];
|
||||
Object.entries(match.groups || {}).forEach(([groupName, groupValue]) => {
|
||||
const groupIndices = indices.groups[groupName] || [-1, -1];
|
||||
groups.push({
|
||||
name: groupName,
|
||||
value: groupValue,
|
||||
start: indices.groups[groupName][0],
|
||||
end: indices.groups[groupName][1],
|
||||
start: groupIndices[0],
|
||||
end: groupIndices[1],
|
||||
});
|
||||
});
|
||||
results.push({
|
||||
|
||||
Reference in new issue
Block a user