Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex from VB to C# (LIKE to Regex)

Tags:

c#

regex

vb.net

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?

like image 874
Ahmed ilyas Avatar asked Nov 22 '25 07:11

Ahmed ilyas


1 Answers

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
}
like image 74
Martin Ender Avatar answered Nov 24 '25 21:11

Martin Ender



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!