diff --git a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.cs b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.cs
index 4a3040b657deb..57588275b0c74 100644
--- a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.cs
+++ b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.cs
@@ -112,7 +112,10 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
})
// Combine all of the generated text outputs into a single batch. We then generate a single source output from that batch.
- .Collect();
+ .Collect()
+
+ // Apply sequence equality comparison on the result array for incremental caching.
+ .WithComparer(new ObjectImmutableArraySequenceEqualityComparer());
// When there something to output, take all the generated strings and concatenate them to output,
// and raise all of the created diagnostics.
@@ -354,5 +357,38 @@ private sealed record class DiagnosticData(DiagnosticDescriptor descriptor, Loca
/// Create a from the data.
public Diagnostic ToDiagnostic() => Diagnostic.Create(descriptor, location, arg is null ? Array.Empty