diff --git a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs index 43c2fdf4169103..ec0a0e2db14bf6 100644 --- a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs +++ b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs @@ -4079,11 +4079,13 @@ void EmitSingleCharRepeater(RegexNode node, bool emitLengthCheck = true) // If we're able to vectorize the search, do so. Otherwise, fall back to a loop. // For the loop, we're validating that each char matches the target node. - // For IndexOf, we're looking for the first thing that _doesn't_ match the target node, + // For Contains{Any}, we're looking for the first thing that _doesn't_ match the target node, // and thus similarly validating that everything does. if (TryEmitIndexOf(requiredHelpers, node, useLast: false, negate: true, out _, out string? indexOfExpr)) { - using (EmitBlock(writer, $"if ({sliceSpan}.Slice({sliceStaticPos}, {iterations}).{indexOfExpr} >= 0)")) + string containsExpr = indexOfExpr.Replace("IndexOf", "Contains"); + + using (EmitBlock(writer, $"if ({sliceSpan}.Slice({sliceStaticPos}, {iterations}).{containsExpr})")) { Goto(doneLabel); }