.net - Regex for a string of n characters -
i want use .net's regex.ismatch function determine if string 8 characters long , matches expression ak-\d\d\d\d[ff]
. so, ak-9442f
match not ak-9442f2
nor ak-9442
. how construct expression?
using static regex.ismatch, can do:
if (regex.ismatch(myteststring, @"^ak-\d{4}[ff]$")) { // passed }
should work purpose. broken down, it's:
^ # must match beginning of string ak- # string literal, "ak-" \d{4} # \d digit, {4} means must repeated 4 times [ff] # either upper or lowercase f $ # must match end of string
Comments
Post a Comment