2023-06-05 18:08:52 +02:00
|
|
|
include::../why-dotnet.adoc[]
|
2023-05-03 11:06:20 +02:00
|
|
|
|
2023-06-05 18:08:52 +02:00
|
|
|
== How to fix it
|
2023-03-22 15:25:58 +01:00
|
|
|
|
2023-06-05 18:08:52 +02:00
|
|
|
=== Code examples
|
2023-03-22 15:25:58 +01:00
|
|
|
|
2023-06-05 18:08:52 +02:00
|
|
|
==== Noncompliant code example
|
2023-03-22 15:25:58 +01:00
|
|
|
|
2023-06-05 18:08:52 +02:00
|
|
|
[source,vbnet,diff-id=1,diff-type=noncompliant]
|
2023-03-22 15:25:58 +01:00
|
|
|
----
|
2023-06-05 18:08:52 +02:00
|
|
|
Sub Regexes(Input As String)
|
|
|
|
Dim Rx As New Regex("[A") ' Noncompliant: unmatched "["
|
|
|
|
Dim Match = Regex.Match(Input, "[A") ' Noncompliant
|
|
|
|
Dim NegativeLookahead As New Regex("a(?!b)", RegexOptions.NonBacktracking) ' Noncompliant: negative lookahead without backtracking
|
|
|
|
Dim NegativeLookbehind As New Regex("(?<!a)b", RegexOptions.NonBacktracking) ' Noncompliant: negative lookbehind without backtracking
|
2023-03-22 15:25:58 +01:00
|
|
|
End Sub
|
|
|
|
----
|
|
|
|
|
2023-06-05 18:08:52 +02:00
|
|
|
==== Compliant solution
|
2023-03-22 15:25:58 +01:00
|
|
|
|
2023-06-05 18:08:52 +02:00
|
|
|
[source,vbnet,diff-id=1,diff-type=compliant]
|
2023-03-22 15:25:58 +01:00
|
|
|
----
|
2023-06-05 18:08:52 +02:00
|
|
|
Sub Regexes(Input As String)
|
2023-03-22 15:25:58 +01:00
|
|
|
Dim Rx As New Regex("[A-Z]")
|
|
|
|
Dim Match = Regex.Match(Input, "[A-Z]")
|
|
|
|
Dim NegativeLookahead As New Regex("a(?!b)")
|
|
|
|
Dim NegativeLookbehind As New Regex("(?<!a)b")
|
|
|
|
End Sub
|
|
|
|
----
|
|
|
|
|
2023-06-05 18:08:52 +02:00
|
|
|
include::../resources-dotnet.adoc[]
|
2023-03-22 15:25:58 +01:00
|
|
|
include::../rspecator.adoc[]
|