include::../why-dotnet.adoc[]

== How to fix it

=== Code examples

==== Noncompliant code example

[source,csharp,diff-id=1,diff-type=noncompliant]
----
void Regexes(string input)
{
    var regex = new Regex("[A");                                                    // Noncompliant
    var match = Regex.Match(input, "[A");                                           // Noncompliant
    var negativeLookahead = new Regex("a(?!b)", RegexOptions.NonBacktracking);      // Noncompliant
    var negativeLookbehind = new Regex("(?<!a)b", RegexOptions.NonBacktracking);    // Noncompliant
}
----

==== Compliant solution

[source,csharp,diff-id=1,diff-type=compliant]
----
void Regexes(string input)
{
    var regex = new Regex("[A-Z]");
    var match = Regex.Match(input, "[A-Z]");
    var negativeLookahead = new Regex("a(?!b)");
    var negativeLookbehind = new Regex("(?<!a)b");
}
----

include::../resources-dotnet.adoc[]
include::../rspecator.adoc[]
