The xxx_yyy_zzz-aaa
string implies that the format is {alphanum}_{alphanum}_{alphanum}-{alphanum}
. The pattern for the {alphanum}
part has already been written by you.
Next, you want to quantify each alphanumeric part since just [A-Za-z0-9]
matches a single alphanum char. Use +
to match 1 or more occurrences, or {3}
to match only 3, or {3,}
to match 3 or more.
That is not all, since you expect the whole string to match the pattern. Hence, you need anchors, ^
to match the start of string and $
(or \z
) to match the end of string.
Thus, I'd recommend
@"^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+-[a-zA-Z0-9]+\z"
See the regex demo.