Microsoft’s latest preview of .NET 7, the forthcoming next version of its software development platform, features enhancements for working with regular expressions and caching.
Downloadable from the Microsoft .NET website, the fourth preview of .NET 7 was published May 10. The production release is due in November.
Microsoft .NET Preview 4 adds remaining planned APIs that add support for span types to the Regex (regular expressions) library. The changes add support for matching with
ReadOnlySpan<char> inputs and overhaul the handling of
The new span-based APIs include:
Regex.IsMatch(ReadOnlySpan<char> input), which indicates whether the regular expression finds a match in the input span.
Regex.Count(ReadOnlySpan<char> input), which searches an input string for all occurrences of a regular expression and returns the number of matches.
Regex.EnumerateMatches(ReadOnlySpan<char> input), which searches an input span for occurrences of a regular expression and returns a
ValueMatchEnumeratorto lazily iterate over the matches.
In other Regex improvements, Microsoft said it has worked to make the code generated by the Regex source generator more readable and easier to debug, and to enable projects with multiple source-generated regular expression patterns to share common code.
Preview 4 also introduces metrics support for
IMemoryCache. The main APIs being added are
MemoryCacheStatistics, which holds cache hit, miss, estimated size, and count for
GetCurrentStatistics, which returns an instance of
MemoryCacheStatistics, or null when the
TrackStatistics flag is not enabled.
Also in Preview 4, Microsoft has finished annotating the
Microsoft.Extensions.* libraries for nullability, introduced an
Activity.Current change event to enhance OpenTelemetry support for observability, and added the
System.Formats.Tar assembly, which contains cross-platform APIs for reading, archiving, writing, and extracting Tar archives.