if(Regex.IsMatch(c1,@"^[A-Za-z]([\*][a-z])*[A-Za-z]+$"))
{
return true;
}
I am trying to write regular expression which specifies that text should start with a letter and end with a letter and it contains "*" in between every alphabet. I don't know how to specify special character in between every alphabet.
答案 0 :(得分:1)
This should do:
^[a-zA-Z](?:\*[a-zA-Z])+$
This will look for the first character at the start of the string, and then look for all combinations of *
followed by a letter.
答案 1 :(得分:0)
If think you are looking for:
^[A-Za-z](?:(?:\*[a-z])*\*[A-Za-z])?$
if uppercase letters are allowed in the middle of the string, you can use this funny way:
^(?!.*\B)[A-Za-z*]+$
(The negative lookahead (?!.*\B)
prevents the string to contain a non-word boundary)