Is regexptranslate('escape') Too Eager?
1 次查看(过去 30 天)
显示 更早的评论
I'm performing regular expression matching on strings of the form
'S:\repo\mrst\code\gitbucket\mrst-core'
which represent pathnames, particularly directories, on a computer. I'm trying to guard against the most trivial errors when using the above as a regular expression so I prepare the expression using code like
pth = 'S:\repo\mrst\code\gitbucket\mrst-core';
pth = regexptranslate('escape', pth)
but the latter returns
S:\\repo\\mrst\\code\\gitbucket\\mrst\-core
which, in addition to escaping the backslash characters, also escapes the dash in the last pathname component and subsequently leads to false negatives in my matches. I thought that dashes were active characters only within ranges like [a-z] and should not otherwise be treated in special ways.
My question then is whether or not I'm using regexptranslate correctly. Is the function supposed to behave in this way? In case it matters, I am using R2014b as my main platform.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!