0

string1 = 'STUDENT001' string2 = 'STUDENT1111'

the regex - re.match('[\d|\D]{0, 10}', string1) # returns the search - student001

the regex - re.match('[\d|\D]{0, 10}', string2) # returns the search - student111

From the above examples, our expected output is - the pattern matches the string1 and the pattern does not match the string2 because the string2 contains 11 characters

here the pattern matches the length of characters in a range of 0 to 10, but how to mention that this pattern does not allow when the length of characters is more than 10

thanks

TBA
  • 1,921
  • 4
  • 13
  • 26
vishak raj
  • 13
  • 4
  • You could also just check the length of the string directly, instead of relying on the regex. – Karl Knechtel Dec 25 '21 at 08:01
  • @karlKnechtel, Actually, I had other conditions, so checking the length with if else statement is not optimal, that's why I am checking with regex with matching pattern – vishak raj Dec 25 '21 at 08:40

0 Answers0