MATLAB 中的正则表达式允许负整数
MATLAB 中的正则表达式是否将其取为负整数,例如“-1”。由于此错误“索引超出矩阵尺寸。”
,我的代码似乎运行良好,并且我知道它与我的数据文件中的负值有关。它在工作区窗口中显示负整数。
关于如何在正则表达式中允许负整数的任何想法
这是代码:
m = regexp(value, 'START=(\d+)', 'tokens');
m2 = regexp(value, 'STOP=(\d+)', 'tokens');
start = cell2mat(m{1});
stop = cell2mat(m2{1});
% Print result
fprintf(fout, 'INSERT INTO cath_domains (pdbcode, cathbegin, cathend) VALUES("%s", %s, %s)\n', domain, start, stop);
Does regular expressions in MATLAB take it a negative integer, such as "-1". My code doesn't seem to run well due to this error "Index exceeds matrix dimensions."
and i know it has something to do with the negative values in my data file. It shows the negative integer in the workspace window.
Any ideas as to how i can allow negative integers in my regular expression
Here's the code:
m = regexp(value, 'START=(\d+)', 'tokens');
m2 = regexp(value, 'STOP=(\d+)', 'tokens');
start = cell2mat(m{1});
stop = cell2mat(m2{1});
% Print result
fprintf(fout, 'INSERT INTO cath_domains (pdbcode, cathbegin, cathend) VALUES("%s", %s, %s)\n', domain, start, stop);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标记
(\d+)
将仅返回数字,而不返回减号等字符。因此,如果有减号,则没有匹配项,m
和/或m2
为空,因此当您尝试索引时会收到错误元胞数组。请尝试
改为,这允许使用可选的减号。
The token
(\d+)
will only return numbers, not characters like the minus sign. Thus, if there is a minus sign, there is no match,m
and/orm2
are empty, and thus you're getting an error when you try to index into the cell arrays.Try
instead, which allows for an optional minus sign.