magic-regexp
magic-regexp copied to clipboard
Unable to convert regex with custom character set to magic-regexp
📚 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?
- I would expect a method for custom character set to be documented on https://regexp.dev/guide/examples
- Possibly I would expect
createInputto 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