Skip to content

enhance apply_regex_substitutions to support use of multi-line patterns, requiring matching all patterns in each file, and use pre-compiled regular expressions #4758

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

Merged
merged 3 commits into from
Mar 3, 2025

Conversation

Flamefire
Copy link
Contributor

@Flamefire Flamefire commented Feb 7, 2025

It might be required to replace patterns with more context, e.g. content of the next or previous line to disambiguate otherwise too generic matches.

Add parameter single_line to enable the old behavior (default) of matching per line and otherwise match the whole text.

Add parameter match_all to require all patterns to match for each file not only at least one.

Also allow to pass regex Pattern object instead of string patterns to allow for additional flags per pattern.
Additionally I collect all error messages for all files and report them together instead of per file for easier resolving.

Note: I set the defaults to be backwards compatible to the current behavior. For EB 5 I'd change match_all to default to True which is likely the safer default.

@Flamefire Flamefire force-pushed the multi-line-replacement branch from c14b549 to 20826c6 Compare February 7, 2025 10:13
It might be required to replace patterns with more context, e.g. content
of the next or previous line to disambiguate otherwise too generic matches.

Add parameter `single_line` to enable the old behavior (default) of
matching per line and otherwise match the whole text.
Add parameter `match_all` to require all patterns to match for each file
not only at least one.
@Flamefire Flamefire force-pushed the multi-line-replacement branch 2 times, most recently from b5fcdce to 9a9d4a3 Compare February 10, 2025 11:21
@Flamefire Flamefire force-pushed the multi-line-replacement branch from 9a9d4a3 to 7e53406 Compare February 10, 2025 11:39
Copy link
Member

@boegel boegel left a comment

Choose a reason for hiding this comment

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

lgtm

@boegel boegel modified the milestones: 4.x, release after 4.9.4 Mar 3, 2025
@boegel boegel changed the title enhance apply_regex_substitutions enhance apply_regex_substitutions to support use of multi-line patterns, requiring matching all patterns in each file, and use pre-compiled regular expressions Mar 3, 2025
@boegel boegel merged commit c0e5aaa into easybuilders:develop Mar 3, 2025
37 checks passed
@Flamefire Flamefire deleted the multi-line-replacement branch March 4, 2025 08:08
@boegel boegel modified the milestones: release after 4.9.4, release after 5.0.0, 5.0.0 Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants