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

조회 수: 1 (최근 30일)
Bård Skaflestad
Bård Skaflestad 2015년 10월 5일
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