[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replac
From: |
Burkart Lingner |
Subject: |
[Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility |
Date: |
Fri, 30 Mar 2012 16:55:52 +0000 |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:11.0) Gecko/20100101 Firefox/11.0 |
Follow-up Comment #7, bug #35911 (project octave):
Here are the MATLAB 2011b/Octave 3.6.1 comparison results as per request:
regexprep('n', '.', 'X')
yields "XX" in both MATLAB and Octave which means neither interprets backslash
escapes in the single-quoted input string.
str = sprintf('anb');
regexprep(str, 'n', 'X')
yields "aXb" in both MATLAB and Octave. However, I wouldn't say that this is
due to interpolation of the regex string but rather an inherent feature of
regular expressions. See for example
regexprep('a.b', 'w', 'X')
which yields "X.X" in both environments. Here "w" is recognized by the regex
engine just like the "n" is in the example above.
Nevertheless both MATLAB and Octave can handle
str = sprintf('anb');
newline = sprintf('n');
regexprep(str, newline, 'X')
and both return "aXb". Not that I would personally use regular expressions
containing un-escaped newlines. The point is that Octave's regexprep function
is already compatible with MATLAB's regarding single-quoting both the input
string and the regular expression string.
----
Regarding an additional configuration variable, it would complicate
interoperable code to something like this:
if strcmp(environment, 'Octave') ...
&& ((version < 3.8) || (~interpolate_single_quotes))
% Octave default: don't interpolate single-quoted strings
repl = 'n';
else
% MATLAB-style: do interpolate regexprep replacement strings
repl = '\n';
end
out = regexprep(in, 'n', repl);
If single-quoted strings in regexprep were unconditionally interpolated, this
would make the if condition a little simpler (granted, a minor improvement)
and would make it possible to omit the if statement altogether once the script
supports only Octave versions 3.8 and newer. The latter may not be desirable
on the release day of 3.8, but what about a few years from now?
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?35911>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility, Burkart Lingner, 2012/03/20
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility, Rik, 2012/03/25
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility, Burkart Lingner, 2012/03/28
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility, Rik, 2012/03/28
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility, John W. Eaton, 2012/03/28
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility, Rik, 2012/03/29
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility, Rik, 2012/03/29
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility,
Burkart Lingner <=
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility, Jordi GutiƩrrez Hermoso, 2012/03/30
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility, Burkart Lingner, 2012/03/30
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility, John W. Eaton, 2012/03/30
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility, John W. Eaton, 2012/03/30
- [Octave-bug-tracker] [bug #35911] Backslash escaping in regexprep replacement string incompatibility, Burkart Lingner, 2012/03/30