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

Unable to convert regex with custom character set to magic-regexp #397

Open
favna opened this issue May 28, 2024 · 0 comments · May be fixed by #399
Open

Unable to convert regex with custom character set to magic-regexp #397

favna opened this issue May 28, 2024 · 0 comments · May be fixed by #399
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@favna
Copy link

favna commented May 28, 2024

📚 Is your documentation request related to a problem?

I am trying to convert the regexp /[A-Za-zÀ-ÖØ-öø-ÿ]\S*/g to magic-regexp, however I cannot figure out how to capture the section of À-ÖØ-öø-ÿ. The first bit of the character set would be covered by letter, but I cannot find any way to provide a custom character set.

So far my conversion is:

const TO_TITLE_CASE = /[A-Za-zÀ-ÖØ-öø-ÿ]\S*/g;
const TO_TITLE_CASE = createRegExp('[A-Za-zÀ-ÖØ-öø-ÿ]', not.whitespace.times.any(), [global]);

However this results in the - being escaped and the resulting regexp to be:

MagicRegExp<"/[A\\-Za\\-zÀ\\-ÖØ\\-öø\\-ÿ]\\S*/g", never, [], "g">

Looking at the source code there simply does not seem to be any way to provide a custom character set, this could possibly be solved by exporting createInput.

🔍 Where should you find it?

  1. I would expect a method for custom character set to be documented on https://regexp.dev/guide/examples
  2. Possibly I would expect createInput to be exported so it can used to achieve a custom character set

ℹ️ Additional context

The regex to be converted is for this file: https://github.com/sapphiredev/utilities/blob/main/packages/utilities/src/lib/toTitleCase.ts

@favna favna added the documentation Improvements or additions to documentation label May 28, 2024
@maige-app maige-app bot added the bug Something isn't working label May 28, 2024
@danielroe danielroe linked a pull request Jun 4, 2024 that will close this issue
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants