简体   繁体   English

最后一次匹配后的Matlab regexp,到字符串的结尾

[英]Matlab regexp after last match, to the end of the string

I'm trying to match everything after the last match of a character (everything after the last "\\". This code works, but I'm wondering if I can do it with a single regexp command. 我试图匹配一个字符的最后一个匹配后的所有内容(最后一个“\\”之后的所有内容。这段代码有效,但我想知道我是否可以用一个regexp命令来完成它。

filename = 'c:\apps\testing\local\blah.txt';
chunks = strread(filename,'%s','delimiter','\\');
fname = chunks{end};

There are two ways to solve this: 有两种方法可以解决这个问题:

[pathName, fileName, extension] = fileparts(filename);

With regex ("after backslash, take all characters that are not a backslash ([^\\\\]*) until the end $ , returning just those characters 'tokens' and don't try to do multiple matches 'once' ") 使用正则表达式(“反斜杠后,将所有不是反斜杠的字符([^\\\\]*)直到结束$ ,只返回那些字符'tokens'并且不要尝试多次匹配'once' ”)

extension = regexp(filename,'\\([^\\]*)$','tokens','once')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM