Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

News regexp subst #413

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

News regexp subst #413

wants to merge 11 commits into from

Conversation

bshifter
Copy link
Member

@bshifter bshifter commented Dec 9, 2024

continuation of #409

refactor to use func-flags to handle flag args

Signed-off-by: shifter <[email protected]>
…to allow up to 3 digits.

The parser now supports up to 3 digits for match group references.
If the reference exceeds this limit, the parser exits and treats it as a
3-digit reference. This change prevents excessive greediness in processing
match group references and improves performance by limiting the reference size.

Additionally, match groups can now include leading zeros, allowing users to
reference match groups with fewer than 3 digits before alphanumeric characters.
For example, \100000000 will be parsed as match group 100, but by using a prefix
like \00100000000, the parser will correctly identify it as match group 1.

Signed-off-by: shifter <[email protected]>
…of regexp_subst match groups

By default, match groups are enabled in regexp_subst. However, this behavior
can now be explicitly disabled by setting the optional named argument
nogroups=true, as shown:
`regexp_subst(target, match_pattern, replace_pattern, nogroups=true);`


Signed-off-by: shifter <[email protected]>
… present

The function now automatically checks the replacement pattern at config
parsing time. If no match group references are found in the pattern, it
will behave as if the 'nogroups' option is enabled, disabling match group
functionality for performance reasons.

Signed-off-by: shifter <[email protected]>
result = regex_subst("baz,foo,bar", /(\w+),(\w+),(\w+)/, "\\2 \\03 \\1")

# Force disable this feature
result = regex_subst("baz,foo,bar", /(\w+),(\w+),(\w+)/, "\\2 \\03 \\1", nogroups=True)
Copy link
Member

Choose a reason for hiding this comment

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

filterx booleans start with lowercase letters.

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