mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 23:00:19 +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', () => {
|
describe('regex-tester', () => {
|
||||||
|
|||||||
@@ -31,21 +31,23 @@ export function matchRegex(regex: string, text: string, flags: string) {
|
|||||||
const captures: Array<GroupCapture> = [];
|
const captures: Array<GroupCapture> = [];
|
||||||
Object.entries(match).forEach(([captureName, captureValue]) => {
|
Object.entries(match).forEach(([captureName, captureValue]) => {
|
||||||
if (captureName !== '0' && captureName.match(/\d+/)) {
|
if (captureName !== '0' && captureName.match(/\d+/)) {
|
||||||
|
const captureIndices = indices[Number(captureName)] || [-1, -1];
|
||||||
captures.push({
|
captures.push({
|
||||||
name: captureName,
|
name: captureName,
|
||||||
value: captureValue,
|
value: captureValue,
|
||||||
start: indices[Number(captureName)][0],
|
start: captureIndices[0],
|
||||||
end: indices[Number(captureName)][1],
|
end: captureIndices[1],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const groups: Array<GroupCapture> = [];
|
const groups: Array<GroupCapture> = [];
|
||||||
Object.entries(match.groups || {}).forEach(([groupName, groupValue]) => {
|
Object.entries(match.groups || {}).forEach(([groupName, groupValue]) => {
|
||||||
|
const groupIndices = indices.groups[groupName] || [-1, -1];
|
||||||
groups.push({
|
groups.push({
|
||||||
name: groupName,
|
name: groupName,
|
||||||
value: groupValue,
|
value: groupValue,
|
||||||
start: indices.groups[groupName][0],
|
start: groupIndices[0],
|
||||||
end: indices.groups[groupName][1],
|
end: groupIndices[1],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
results.push({
|
results.push({
|
||||||
|
|||||||
Reference in new issue
Block a user