Is regexptranslate('escape') Too Eager?
1 view (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!