I am working on some C# code which uses the .NET class Microsoft.VisualBasic.CompilerServices.LikeOperator
. (Some additional context: I am porting this code to target .NET Standard 2.0, which does not support that class. It is missing from the .NET Standard 2.0 flavor of the Microsoft.VisualBasic nuget package. So I would like to replace the usage of LikeOperator
, but unfortunately there is other code and maybe even end users which depend on the pattern language.)
While playing with LikeOperator.LikeString
to make sure that I understand exactly what it does, I got an unexpected result. I used the pattern "foo*?bar"
to express that I want to match any string which starts with "foo"
, ends with "bar"
, and has one or more characters in between.
However, the following call unexpectedly returns true
:
LikeOperator.LikeString("foobar", "foo*?bar", CompareMethod.Text)
As far as I understand, the ?
wildcard should force at least one character to be present between foo and bar, so I don't understand this result. Are these adjacent *?
wildcards a special case?
edit: the like
operator does seem to work as expected when tested in the VB.NET implementation of mono 6.12.0. So there seems to be a difference between the .NET Framework and mono here. Could this actually be a bug in Microsoft's implementation?