Regex from VB to C# (LIKE to Regex)

c#, regex, vb.net

Solution

Based on Damien_The_Unbeliever's link, I assume that your pattern matches a literal `*`, 14 arbitrary characters and then a literal `8`.

Then this would be your regex:

@"^\*.{14}8$"

Note that `.` will not generally match line breaks. If you need it to, then set the `SingleLline` option.

Match match = Regex.Match(input, @"^\*.{14}8$", RegexOptions.Singleline)

if (match.Success)
{
    // string has valid format
}

Problem

So, VB6/VB.NET has a `Like` keyword, which is kind of like a Regex. I know what this is doing but I am not an expert in Regex and was hoping someone could kindly help (AND I want to use Regex and not string specific stuff like IndexOf/get the last char): VB code: ``` If (someDataStr Like "[*]??????????????8") Then ... end if ``` So I am focusing on this: `"[*]??????????????8"` what would this be in terms of a Regex expression?

Original source