Skip to content

Support RegExp groups - #18

Merged
AndyReifman merged 6 commits into
AndyReifman:mainfrom
orjandesmet:feature/regex-groups
Sep 4, 2025
Merged

Support RegExp groups#18
AndyReifman merged 6 commits into
AndyReifman:mainfrom
orjandesmet:feature/regex-groups

Conversation

@orjandesmet

Copy link
Copy Markdown
Contributor

This would add support for RegExp groups as suggested in #15

Examples (also added to README):

In a string There is some target-words-123456 in a sentence the pattern target-(?<name>[a-zA-Z]+)-(?<idnr>[0-9]+) allows the following replacements:

replacement value
{0} "target-words-123456"
{1} "words"
{2} "123456"
{pattern} "target-words-123456"
{name} "words"
{indr} "123456"

A link https://example.com/{name}/{idnr} would then become https://example.com/words/123456

@AndyReifman

Copy link
Copy Markdown
Owner

I'll try to take a look at this shortly.

I'd call this a minor version change vs patch as we're adding some additional functionality.

Comment thread replacePattern.ts Outdated
@@ -0,0 +1,27 @@
export function replacePattern(link: string, pattern: string, innerWord: string) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: pattern should be RegExp to match declaration in main.ts

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you're willing, could you add some docstrings/comments to these functions to help with future development.

I need to do that for the existing code still but this could be a start.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated type in c64614c
Added docstrings in 2a74af0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change sadly introduced a bug, see #19

Comment thread replacePattern.ts Outdated
}, link);
}

function findGroups(innerWord: string, pattern: string): string[][] {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: RegExp for pattern here as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in c64614c

Comment thread README.md Outdated
| `{name}` | "words" |
| `{number}` | "123456" |

A link `https://example.com/{name}/{number}` would then become `https://example.com/words/123456`

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this example could be clarified some more.

Maybe a sentence at the end showing what your initial input example sentence (There is some target-words-123456 in a sentence) would look like after the plugin runs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 4577458

@orjandesmet

Copy link
Copy Markdown
Contributor Author

I'll try to take a look at this shortly.

I'd call this a minor version change vs patch as we're adding some additional functionality.

Thanks for reviewing!

@AndyReifman
AndyReifman merged commit d546c4a into AndyReifman:main Sep 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants