Is regexptran​slate('esc​ape') Too Eager?

2 views (last 30 days)
Bård Skaflestad
Bård Skaflestad on 5 Oct 2015
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.

Answers (0)

Community Treasure Hunt

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

Start Hunting!