Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a ReSharper annotation for regex highlighting?

I like to add annotations like StringFormatMethod to my formatting methods, so ReSharper highlights format parameters etc.

ReSharper also has syntax highlighting for regular expressions, and I would like the same treatment of regex patterns in my own extension method ReplaceRegex:

Regular expresssions syntax highlighting

Notice how the \s* is highlighted only in Regex.Replace.

I looked in the Jetbrains.Annotations namespace, but could not find any relevant attributes. Is there currently no way to do this?

like image 331
Geir Sagberg Avatar asked Oct 11 '25 10:10

Geir Sagberg


1 Answers

Turns out the problem was I had an old version of Jetbrains.Annotations.

The attribute I was looking for was RegexPatternAttribute, found in JetBrains.Annotations.

Here is my extension method with the attribute:

    public static string ReplaceRegex(this string str, [RegexPattern] string pattern, string replacement, RegexOptions options = RegexOptions.None) {
        return Regex.Replace(str, pattern, replacement, options);
    }

Now I get the fancy coloring for my extension method: Regex syntax highlighting

Thanks to @AakashM for the comment with the answer!

like image 117
Geir Sagberg Avatar answered Oct 14 '25 00:10

Geir Sagberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!