Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 前后的regexp编号'-';_Matlab - Fatal编程技术网

Matlab 前后的regexp编号'-';

Matlab 前后的regexp编号'-';,matlab,Matlab,1) 我有以下格式的地物名称和数字:“地物编号:字母/数字/\s”。例如,“图10-11:20辆车的速度” 我得到的结果如下所示: regexp(cell2mat(regexp('Figure 10-11: speed_of_20_cars','[0-9]+-[0-9]+','match')),'(?<!:)-(?!:)','split') 这给了一个双格:10。再说一次,必须有一种方法只使用一个regexp就可以做到这一点 提前谢谢你。这就是你要找的吗 s=regexp('Figure

1) 我有以下格式的地物名称和数字:“地物编号:字母/数字/\s”。例如,“图10-11:20辆车的速度”

我得到的结果如下所示:

regexp(cell2mat(regexp('Figure 10-11: speed_of_20_cars','[0-9]+-[0-9]+','match')),'(?<!:)-(?!:)','split')
这给了一个双格:10。再说一次,必须有一种方法只使用一个regexp就可以做到这一点


提前谢谢你。

这就是你要找的吗

s=regexp('Figure 10-11: speed_of_20_cars','([0-9]+)[-:]','tokens')
ids=cellfun(@str2num,[s{:}])

对非常感谢。啊……‘代币’。从来没用过。[-:]如何使用“令牌”?我认为它的意思是“-”或“:”,但它如何知道它是在前/后/之间呢?
“tokens”
选项基本上返回您使用
()
运算符定义的变量。我要求regexp查找后跟“-”(第一个数字)或“:”(第二个数字)的数字。看见
s=regexp('Figure 10-11: speed_of_20_cars','([0-9]+)[-:]','tokens')
ids=cellfun(@str2num,[s{:}])