bor*_*ted 2 regex matlab strsplit
输入字符串是:
InputStr1 = 'this-is-a-boy-5';
InputStr2 = 'this23-is-a-boy-10';
InputStr3 = 'this-41';
Run Code Online (Sandbox Code Playgroud)
输出应该是:
Output1 = ['this-is-a-boy'] [5]
Output2 = ['this23-is-a-boy'] [10]
Output3 = ['this'] [41]
Run Code Online (Sandbox Code Playgroud)
我想将这些字符串分成两部分,这样我就可以将第一个字符串和最后一个字符分开.我试过strsplit()但它没有帮助.
这应该工作(假设总有最后的数字)
data = 'this-is-a-boy-5'
toks = regexp(data, '(.*)-(\d+)$', 'tokens');
display(toks)
Run Code Online (Sandbox Code Playgroud)
如果你想使用,strsplit你可以使用它
toks = strsplit(data, '-(?=\d+$)', 'DelimiterType', 'RegularExpression');
display(toks)
Run Code Online (Sandbox Code Playgroud)