Does anyone know the pure witchcraft regex expresion to remove all non-numeric characters from the beginning of a string?
For example, in each case I want to be left with 1234567 :
*&%&%^*hjghgfgyh u gyu1234567
+1234567
+001234567
hhrrttdghdhjfhfgrjdgfdhjfdkfjfihukjhr nuhh frelheruhehurhrxffr1234567
This is not for Python specifically (it’s actually for Lua) but I’m pretty sure the regex expression would be the same regardless.
I just cannot find the right words to google this.
I also usually use a regex checker to test what I’m trying to do: https://regex101.com/ (but maybe that’s obvious).
To be clear, in your case, are you only trying to remove the non-numeric characters at the beginning? So if you had hello1234567world, do you want to be left with 1234567world?
(I have sympathy for you, I just test positive this morning )
[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)