Matching groups?
victorperin opened this issue · comments
I couldn't find a way to match groups. For example:
regexifyString({
pattern: /\[(?<id>.+)\]\{(?<name>.+)\}/g,
decorator: (id, name) => (<item b={id} c={name} />),
input: 'a[b]{c}',
})
// to output:
// [ 'a', <item b='b' c='c' />, '']
Is this possible?
Dear Victor, hi
I have to investigate that in the next few weeks
If you have any suggestions it would be very helpful to speed up this feature release process )
https://github.com/kas-elvirov/regexify-string/blob/master/src/index.ts#L24
You can pass the whole result here with the third argument, the groups will be next after the 0 element of the array.
const decoratedMatch = decorator(match, matchIndex, result);
@victorperin @G1K is this functionality still needed?
this function will definitely be useful, but it is possible to design it in a more beautiful way. My solution suits me and I'm already using it).
@G1K could you share your version?
The line from the message above is already my solution) result
contains the result of exec , it will already contain named groups if it was in the regular expression.
const decoratedMatch = decorator(match, matchIndex);
>>
const decoratedMatch = decorator(match, matchIndex, result);
result.groups
Hi guys (@G1K @victorperin )
Sorry for so late reply. Just published new version with suggestion of @G1K (many thanks for that)