Search code examples
regexnotepad++

Turn Cyrilic text to lowers case


I want to convert the text to lowercase, but it contains Cyrillic characters and remains uppercase.

RegEx sandbox: https://regex101.com/r/GFuZYc/1

How do I change the replace parameter to make it work?

The text is:

WWWWWWWWW
wwwwwWWWWWWWwwwwwww
wwwwwwwwwwwwww
ЫЫЫЫЫЫЫЫЫЫЫ
ыыыыыыыыЫЫЫЫЫЫЫЫЫыыыыыыыы

Find:

(\w+|[ыЁёА-я]+)

Replace:

\L$1

Result:

wwwwwwwww
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwww
ЫЫЫЫЫЫЫЫЫЫЫ
ыыыыыыыыЫЫЫЫЫЫЫЫЫыыыыыыыы

Solution

  • Notepad++:

    This is not possible by default, because Notepad++ doesn't have built-in support for handling Unicode characters like Cyrillic characters directly in regex.

    Notepad++ workaround:

    Try this:

    1. Install PythonScript Plugin.

    2. Create a PythonScript: Once the PythonScript plugin is installed, you can create a new PythonScript by going to Plugins > PythonScript > New Script.

    3. Write Python code for the created Script, which handles the wished task: editor.rereplace(r'(\w+|[ЁёА-я]+)', lambda m: m.group(0).lower())

    4. Run the Script: Go to Plugins > PythonScript > Scripts > YourScriptName to run the script.

    Side info: Javascript:

    In Javascript, you can use toLocaleLowerCase(), which handles Unicode characters properly. This will correctly convert both Latin and Cyrillic characters to lowercase:

    let text = "WWWWWWWWW\nwwwwwWWWWWWWwwwwwww\nwwwwwwwwwwwwww\nЫЫЫЫЫЫЫЫЫЫЫ\nыыыыыыыыЫЫЫЫЫЫЫЫЫыыыыыыыы";
    
    let lowercaseText = text.toLocaleLowerCase();
    console.log(lowercaseText);