import sys
import re
a = sys.argv[1]
print(a)
m1 = re.search("[^0-9\.]", a) # str
m2 = re.search("[0-9\.]", a) # num
if m1 and m2:
print("m1.start(),m2.start():",m1.start(),m2.start())
if m1.start() > m2.start():
ret = a[:m1.start()]
else:
ret = a[m2.start():]
print("ret:",ret)
m3 = re.search("[^0-9\.]", ret)
if m3:
ret = ret[:m3.start()]
elif m1:
# only str
ret = ""
elif m2:
# only num
ret = a
print("ret:",ret)
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme