# HG changeset patch # User Rik # Date 1431445613 25200 # Node ID 89616a98b02e0f9cff77601f4ed9b5c58b755a3c # Parent 5212cda4ac0e36cdfeed1ec5bf939cffe17892a1 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. diff -r 5212cda4ac0e -r 89616a98b02e scripts/strings/regexptranslate.m --- a/scripts/strings/regexptranslate.m Sun May 10 21:37:19 2015 -0700 +++ b/scripts/strings/regexptranslate.m Tue May 12 08:46:53 2015 -0700 @@ -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 regexptranslate ()