Mercurial > hg > octave-nkf
diff scripts/strings/regexptranslate.m @ 20390:89616a98b02e
regexptranslate.m: Fix 'escape' option list of special chars (bug #45084).
Also speed up 'wildcard' option by 44% by using strrep rather than regexprep.
* regexptranslate.m: Explicitly list all all special regexp chars in the
regular expression which escapes them. Replace regexprep calls with strrep
function calls in 'wildcard' option processing.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 12 May 2015 08:46:53 -0700 |
parents | df437a52bcaf |
children |
line wrap: on
line diff
--- a/scripts/strings/regexptranslate.m +++ b/scripts/strings/regexptranslate.m @@ -64,11 +64,11 @@ op = tolower (op); if (strcmp ("wildcard", op)) - y = regexprep (regexprep (regexprep (s, '\.', '\.'), - '\*', '.*'), - '\?', '.'); + y = strrep (strrep (strrep (s, '.', '\.'), + '*', '.*'), + '?', '.'); elseif (strcmp ("escape", op)) - y = regexprep (s, '([^\w])', '\\$1'); + y = regexprep (s, '([][(){}.*+?^$|\\])', '\\$1'); else error ("regexptranslate: invalid operation OP"); endif @@ -77,7 +77,7 @@ %!assert (regexptranslate ("wildcard", "/a*b?c."), "/a.*b.c\\.") -%!assert (regexptranslate ("escape", '$.?[abc]'), '\$\.\?\[abc\]') +%!assert (regexptranslate ("escape", '^.?[abc]$'), '\^\.\?\[abc\]\$') ## Test input validation %!error <Invalid call to regexptranslate> regexptranslate ()