import regex st = """ <!-- Start of page --> <HTML> <!-- Start of head --> <HEAD> <TITLE>My Title</TITLE> <!-- Page title --> </HEAD> <!-- Body --> <BODY> """ pat = regex.compile(r"<!-{2,}(.*?)-{2,}>") st2 = pat.sub(r'\U\1\E', st) print(st2) In the above code, I am trying to implement a Case Conversion operation using "regex" module(indeed used "re" module too) and what I want to do is To convert all text between comments written in HTML to upper Case, for example <!-- Start of page --> TO <!-- START OF PAGE -->, but When I try to do so, With this syntactically correct code, that should have worked It gives me this error.
Traceback (most recent call last): File "C:/Users/m.m/PycharmProjects/untitled9/source.py", line 13, in <module> st2 = pat.sub(r'\U\1\E', st) File "C:\Users\m.m\.virtualenvs\untitled5\lib\site-packages\regex\regex.py", line 676, in _compile_replacement_helper is_group, items = _compile_replacement(source, pattern, is_unicode) File "C:\Users\m.m\.virtualenvs\untitled5\lib\site-packages\regex\_regex_core.py", line 1696, in _compile_replacement return False, [parse_repl_hex_escape(source, HEX_ESCAPES[ch], ch)] File "C:\Users\m.m\.virtualenvs\untitled5\lib\site-packages\regex\_regex_core.py", line 1764, in parse_repl_hex_escape source.string, source.pos) regex._regex_core.error: incomplete escape \U at position 3 It seem's that it does not know what is the purpose of \U and \L and gives "incomplete escape error"
I am currently using python 3.7 and I have tried to do so, with "re" module too, but it does not work.
I wanted to know , what is the problem ?, I have seen many books used to do case conversion with regex. but The fact that "Why should not this work ?" has been an enigma for me.
Is the problem from the syntax, or does it originate from the python implementation of regex itself, that does not support such operation to convert cases?
In This question, I am trying to convert the text using \E etc, or formally "using CaseConversion in regex"
\Uand\Lyet your code contains\Uand\E. Which is it?remodule’s inability to handle certain valid expressions.\E, do you know of any good resources for either one?