diff NEWS @ 15541:9db32cabeacf

Fix backslash handling in regexp pattern (Bug #37092) * NEWS: Give an example of how escape sequence processing in single-quoted regular expressions works. * libinterp/corefcn/regexp.cc(do_regexp_string_escapes): Rename to do_regexp_ptn_string_escapes. Only sequence to expand is '\b' for backspace. Others are handled by PCRE. * libinterp/corefcn/regexp.cc(do_regexp_rep_string_escapes): New function to do escape sequence processing for the replacement string since the sequences to expand differ from that of the regexp pattern. * liboctave/util/regexp.cc(regexp::replace): Process backslashes in replacement string so that '\$1' results in '$1' rather than replacement with first capture buffer.
author Rik <rik@octave.org>
date Wed, 17 Oct 2012 20:13:19 -0700
parents 7a0a202fedfe
children acf0addfc610
line wrap: on
line diff
--- a/NEWS	Wed Oct 17 15:56:33 2012 -0700
+++ b/NEWS	Wed Oct 17 20:13:19 2012 -0700
@@ -56,9 +56,16 @@
     where the pattern is actually the assertion '^' or start-of-line.
 
  ** For compatibility with Matlab, the regexp, regexpi, and regexprep
-    functions now process backslash escapes in single-quoted pattern
+    functions now process backslash escape sequences in single-quoted pattern
     strings.  In addition, the regexprep function now processes backslash
-    escapes in single-quoted replacement strings.
+    escapes in single-quoted replacement strings.  For example,
+    
+    regexprep (str, '\t', '\n')
+
+    would search the variable str for a TAB character (escape sequence \t)
+    and replace it with a NEWLINE (escape sequence \n).  Previously the
+    expression would have searched for a literal '\' followed by 't' and
+    replaced the two characters with the sequence '\', 'n'.
 
  ** Redundant terminal comma accepted by parser