[OFF-TOPIC] - Regex - strip leading non-numeric chars

On the server side:
re.sub(r'^[^\d]*', '', txt)

  • [abc] matches any character inside, either a, b or c
  • [^abc] matches any character that is not inside, all but a, b or c
  • \d matches any numerical character
  • [^\d] matches any non numerical character
  • [^\d]* matches a repetition of zero or more non numerical character
  • ^[^\d]* matches zero or more non numerical character starting from the beginning of the string (yes, the ^ has a meaning if it’s the first character in the pattern, another meaning if it’s the first inside [])

On the client side re.sub does not exist, so you can use re_sub, which behaves slightly differently from the real re.sub:
re_sub(r'^[^\d]*(.*)', r'\1', txt)

2 Likes