All I want is to grab the first 3 numeric characters of string:
st = '123_456'
import re
r = re.match('([0-9]{3})', st)
print r.groups()[0]
Am I doing the right thing for grabbing first 3 characters?
This returns
123but what if I want to get the first 3 characters regardless of numbers and alphabets or special characters?
When given 12_345, I want to grab only 12_
Thanks,
'12_345_678'it should grab'345')