Hi,
What will be the regular expression to accept 'CP123' First two letters CP and other 3 or 4 or 5 nos.
Hi,
What will be the regular expression to accept 'CP123' First two letters CP and other 3 or 4 or 5 nos.
even if your question it's not very clear this should work:
r'^CP[0-9]{3,5}$'
This will match your requirements:
^CP\d{3,5}$
The ^ matches the beginning of the string, so that it doesn't allow any characters to the left of "CP".
\d matches a digit, {3,5} makes it match 3-5 digits.
The $ matches the end of the string, so that it doesn't allow any characrers after the digits.
If you are using the regular expression in a validation control, you can remove the ^ and $, as that is added by the control:
CP\d{3,5}
Regex regxExp = new Regex( "CP[0-9]{3,5}" );
bool result = regxExp.IsMatch( //Expression );
As per update in comments:
CP\d{1,5}
if you want one to five digits following CP. Otherwise use
CP\d+
if you just want CP followed by at least one digit.