【发布时间】:2017-12-14 23:35:39
【问题描述】:
我有这样一个字符串:
msg='123abc456def'
现在我需要拆分msg并得到如下结果:
['123', 'abc', '456', 'def']
在 python 中,我可以这样做:
pattern = re.compile(r'(\d+)')
res = pattern.split(msg)[1:]
如何在 bash 脚本中获得相同的结果?
我试过这样但它不起作用:
IFS='[0-9]' # how to define IFS with regex?
echo ${msg[@]}
【问题讨论】:
-
为什么不直接调用你的 Python 脚本呢?