bugGNU Octave - Bugs: bug #37092, backslash escape character in...


bug #37092: backslash escape character in regexp

Submitted by:  Guillaume <gyom>
Submitted on:  Tue 14 Aug 2012 12:08:02 PM UTC  
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  Rik <rik5>
Originator Name:  Guillaume Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Thu 18 Oct 2012 03:18:13 AM UTC, comment #10:

I fixed this problem in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/9db32cabeacf). You will need to build from Mercurial sources with a version greater than or equal to 15541:9db32cabeacf in order to see the fix.

Rik <rik5>
Project AdministratorIn charge of this item.
Thu 23 Aug 2012 04:43:45 PM UTC, comment #9:

On my local machine, with my patch applied, your latest test runs fine so I think the single patch will fix both problems.

Rik <rik5>
Project AdministratorIn charge of this item.
Thu 23 Aug 2012 04:02:54 PM UTC, comment #8:

Thanks for the update Rik. If it helps, I can do some tests if you give me a patch.

Perhaps totally unrelated, but I noticed another problem with regexp:

MATLAB returns

as expected, while Octave returns empty fields.

Guillaume <gyom>
Wed 22 Aug 2012 09:02:01 PM UTC, comment #7:

This small little behavior has exposed some real problems in the regexprep code. I've had to rewrite a large amount of C++ code. I've got a solution that works now, but I want to run some of it by the octave-maintainers list before committing the changes.

Rik <rik5>
Project AdministratorIn charge of this item.
Thu 16 Aug 2012 10:42:11 AM UTC, comment #6:

Thanks for looking into this.
With MATLAB R2012a, I get:

Guillaume <gyom>
Thu 16 Aug 2012 12:18:07 AM UTC, comment #5:

Okay, I've done some digging and Octave is not quite handling things correctly. Can you run a few tests on Matlab to see how they interpret things?

Rik <rik5>
Project AdministratorIn charge of this item.
Wed 15 Aug 2012 04:16:52 PM UTC, comment #4:

I'm going to re-open this issue. From your testing, it appears that Octave is interpreting escape character sequences twice which is not correct. I am going to change the Item Group to "Matlab Compatibility" since that is what is really being chased here.

What I think is going on is the following:

I am building a debug version of Octave and will check this out with gdb.

Rik <rik5>
Project AdministratorIn charge of this item.
Wed 15 Aug 2012 11:21:21 AM UTC, comment #3:

Thanks for your comments.

With MATLAB R2012a, I get this:

Let me know if you need other user cases.
I came across this with some MATLAB code I use to escape a string for insertion in LaTeX:
I am not sure how to write some code that will work similarly for both Octave and MATLAB.

Guillaume <gyom>
Tue 14 Aug 2012 10:26:13 PM UTC, comment #2:

I added some extra documentation about this in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/8593bed236f1). Hopefully this helps with understanding why we have to do this now.

Rik <rik5>
Project AdministratorIn charge of this item.
Tue 14 Aug 2012 07:36:31 PM UTC, comment #1:

This is the new behavior of regexp and regexprep in order to be Matlab-compatible. Quoting from the NEWS file which lists significant changes from the last revision:

So, patterns like '\\' really look like "\\" which collapses to just "\" and this causes the problem. It would be useful, if you have access to Matlab, to verify that they haven't done a special case for '\\'. I rather doubt it though.

Either add an extra backslash when using escape sequences like "\n" or look at the regexptranslate function for another option.

Rik <rik5>
Project AdministratorIn charge of this item.
Tue 14 Aug 2012 12:08:02 PM UTC, original submission:

Using the backslash escape character returns an error in regexprep and Octave dev with this call:

while it does not return the correct answer here:

It is fine with Octave 3.6.2.

Guillaume <gyom>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by gyom (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    Thu 18 Oct 2012 03:18:13 AM UTC rik5 StatusIn Progress => Fixed
        Open/ClosedOpen => Closed
    Thu 06 Sep 2012 09:05:44 PM UTC rik5 StatusConfirmed => In Progress
        Assigned toNone => rik5
    Wed 15 Aug 2012 04:16:52 PM UTC rik5 Item GroupIncorrect Result => Matlab Compatibility
        StatusNeed Info => Confirmed
        Open/ClosedClosed => Open
    Tue 14 Aug 2012 07:36:31 PM UTC rik5 CategoryNone => Libraries
        StatusNone => Need Info
        Open/ClosedOpen => Closed

    Back to the top

    Powered by Savane 3.3