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


bug #37092: backslash escape character in regexp

Submitted by:  Guillaume <gyom>
Submitted on:  Tue Aug 14 12:08:02 2012  
Category: LibrariesSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: FixedAssigned to: Rik <rik5>
Originator Name: GuillaumeOpen/Closed: Closed
Release: devOperating System: Any

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

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


(Jump to the original submission Jump to the original submission)

Thu Oct 18 03:18:13 2012, 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 Aug 23 16:43:45 2012, 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 Aug 23 16:02:54 2012, 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 Aug 22 21:02:01 2012, 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 Aug 16 10:42:11 2012, comment #6:

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

Guillaume <gyom>
Thu Aug 16 00:18:07 2012, 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 Aug 15 16:16:52 2012, 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 Aug 15 11:21:21 2012, 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 Aug 14 22:26:13 2012, 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 Aug 14 19:36:31 2012, 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 Aug 14 12:08:02 2012, 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 File(s):

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


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

    Do you think this task is very important?
    If so, you can click here to 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 Oct 18 03:18:13 2012rik5StatusIn Progress=>Fixed
    Thu Sep 6 21:05:44 2012rik5StatusConfirmed=>In Progress
      Assigned toNone=>rik5
    Wed Aug 15 16:16:52 2012rik5Item GroupIncorrect Result=>Matlab Compatibility
      StatusNeed Info=>Confirmed
    Tue Aug 14 19:36:31 2012rik5CategoryNone=>Libraries
      StatusNone=>Need Info

    Back to the top

    Powered by Savane 3.1-cleanup1