diff --git a/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionImpl.java
index 620ec3090653..59478edaa4dd 100644
--- a/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionImpl.java
+++ b/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionImpl.java
@@ -40,6 +40,7 @@ import com.jetbrains.python.psi.types.TypeEvalContext;
import one.util.streamex.StreamEx;
import org.intellij.lang.regexp.DefaultRegExpPropertiesProvider;
import org.intellij.lang.regexp.RegExpLanguageHost;
+import org.intellij.lang.regexp.UnicodeCharacterNames;
import org.intellij.lang.regexp.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -422,4 +423,14 @@ public class PyStringLiteralExpressionImpl extends PyElementImpl implements PySt
public String[][] getKnownCharacterClasses() {
return myPropertiesProvider.getKnownCharacterClasses();
}
+
+ @Override
+ public boolean supportsNamedCharacters(RegExpNamedCharacter namedCharacter) {
+ return LanguageLevel.forElement(this).isAtLeast(LanguageLevel.PYTHON38);
+ }
+
+ @Override
+ public boolean isValidNamedCharacter(RegExpNamedCharacter namedCharacter) {
+ return UnicodeCharacterNames.getCodePoint(namedCharacter.getName()) >= 0;
+ }
}
diff --git a/python/testData/highlighting/namedUnicode.py b/python/testData/highlighting/namedUnicode.py
new file mode 100644
index 000000000000..e0085f668085
--- /dev/null
+++ b/python/testData/highlighting/namedUnicode.py
@@ -0,0 +1,3 @@
+import re
+re.match(r'\N{LESS-THAN SIGN}', '<')
+re.match(r'\N{LESS-THAN SIG}', '<')
\ No newline at end of file
diff --git a/python/testData/highlighting/namedUnicodeBefore38.py b/python/testData/highlighting/namedUnicodeBefore38.py
new file mode 100644
index 000000000000..28fc38afca48
--- /dev/null
+++ b/python/testData/highlighting/namedUnicodeBefore38.py
@@ -0,0 +1,3 @@
+import re
+re.match(r'\N{LESS-THAN SIGN}', '<')
+re.match(r'\N{LESS-THAN SIG}', '<')
\ No newline at end of file
diff --git a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java
index 44ad702fd36f..0b052a9b9dc1 100644
--- a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java
+++ b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java
@@ -436,6 +436,16 @@ public class PythonHighlightingTest extends PyTestCase {
doTest(LanguageLevel.PYTHON37, false, false);
}
+ // PY-36004
+ public void testNamedUnicodeBefore38() {
+ doTest(LanguageLevel.PYTHON37, false, false);
+ }
+
+ // PY-36004
+ public void testNamedUnicode() {
+ doTest(LanguageLevel.PYTHON38, false, false);
+ }
+
@NotNull
private static EditorColorsScheme createTemporaryColorScheme() {
EditorColorsManager manager = EditorColorsManager.getInstance();