diff --git a/RegExpSupport/src/org/intellij/lang/regexp/inspection/RegExpSimplifiableInspection.java b/RegExpSupport/src/org/intellij/lang/regexp/inspection/RegExpSimplifiableInspection.java index 6e175fc47feb..4c0004233d68 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/inspection/RegExpSimplifiableInspection.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/inspection/RegExpSimplifiableInspection.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.intellij.lang.regexp.inspection; import com.intellij.codeInspection.*; @@ -62,7 +62,7 @@ public class RegExpSimplifiableInspection extends LocalInspectionTool { if (elements.length == 1) { final RegExpClassElement element = elements[0]; if (element instanceof RegExpPosixBracketExpression) return; - if (!(element instanceof RegExpCharRange)) { + if (!(element instanceof RegExpCharRange) && !(element instanceof RegExpIntersection)) { if (!(element instanceof RegExpChar) || !"{}().*+?|$".contains(element.getText())) { // [a] -> a registerProblem(regExpClass, element.getUnescapedText()); diff --git a/RegExpSupport/test/org/intellij/lang/regexp/inspection/RegExpSimplifiableInspectionTest.java b/RegExpSupport/test/org/intellij/lang/regexp/inspection/RegExpSimplifiableInspectionTest.java index 9ac0cb2a8c4e..558f84d7172e 100644 --- a/RegExpSupport/test/org/intellij/lang/regexp/inspection/RegExpSimplifiableInspectionTest.java +++ b/RegExpSupport/test/org/intellij/lang/regexp/inspection/RegExpSimplifiableInspectionTest.java @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.intellij.lang.regexp.inspection; import com.intellij.codeInspection.CommonQuickFixBundle; @@ -37,6 +37,11 @@ public class RegExpSimplifiableInspectionTest extends RegExpInspectionTestCase { highlightTest("[0-9abc]"); // no warn; replacing with \d is not equivalent in Unicode context } + public void testIntersection() { + highlightTest("^[\\p{ASCII}&&[^@]]+@[\\p{ASCII}&&[^@]]+$"); + highlightTest("[\\W&&\\S]"); + } + public void testSingleElementClass() { doTest("[a]", "a"); }