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

Add Regex Modifier #568

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add Regex Modifier #568

wants to merge 1 commit into from

Conversation

shuoyangd
Copy link
Contributor

Description

Add a modifier that performs regex replacements.

Usage

regex_params = [
    {"pattern": "ö", "repl": "o"},
    {
        "pattern": "[^ !$%',-.0123456789;?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/:]",
        "repl": "",
    },
]

modifier = RegexModifier(regex_params)
# "Nein, es ist möglich🙃 " -> replacement ö ->
# "Nein, es ist moglich🙃 " -> remove anything other than alphanumeric characters and punctuations
# "Nein, es ist moglich " -> remove extra spaces -> "Nein, es ist moglich"
output = modifier.modify_document("Nein, es ist möglich🙃 ")  # returns "Nein, es ist moglich"

Checklist

  • I am familiar with the Contributing Guide.
  • New or Existing tests cover these changes.
  • The documentation is up to date with these changes.

Signed-off-by: Shuoyang Ding <[email protected]>
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.

1 participant