I want to take a string (Example: TestExample123) and cut off the numbers after a certain set of characters (Giving output 123) but am not aware of any way I could do this. Any help would be great, but do note I am fairly new to coding and as such may not be able to do insanely advanced stuff.
Thanks.
Maybe not the best way, but definitely a good start is trying to use RegEx.
import re
reg = "\d"
text = "TestExample123"
text_2 = "Test123Example123"
regexed_text = re.sub(reg, "", text))
regexed_text_2 = re.sub(reg, "", text_2))
This gives regexed_text = "TestExample"
and also regexed_text_2 = "TestExample"
re.sub(reg, "", text)
substitutes all of the reg
regex matching elements with empty ( ""
) in the given input string variable text
\\d
means any numeric digit
Check out RegEx patterns for more info: rexegg.com .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.