Is regexptran​slate('esc​ape') 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 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by