bugGNU Octave - Bugs: bug #49451, matching beginning/end of a word...

 
 

bug #49451: matching beginning/end of a word does not work

Submitted by:  Francesco Potortì <pot>
Submitted on:  Thu 27 Oct 2016 01:43:01 AM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: devOperating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Fri 04 Nov 2016 03:19:54 PM UTC, comment #3:

I fixed regexp and regexprep to rewrite the pattern for double quoted strings (which was already being done for single quoted strings) before processing by PCRE. This was done on the stable branch here (http://hg.savannah.gnu.org/hgweb/octave/rev/e6fac42c8d56).

There is still a small quirk in that the replacement string, when using double quoted strings, does not accept the matlab syntax for octal or hex. Octave does accept ordinary syntax for octal and hex, and someone transporting code from Matlab to Octave would be using single quotes anyways where this already works. In other words, I'm not too bothered by it, but if someone wants to change that as well they can.

Rik <rik5>
Project Administrator
Thu 27 Oct 2016 04:12:25 PM UTC, comment #2:

As a temporary workaround, use single quotes to avoid interpretation of escape sequences by the Octave interpreter. This also tends to make the patterns more readable which is why I always do this.

The issue is likely to be that double quoted strings are being run through do_string_escapes twice. First, by the Octave interpreter and then a second time by regexprep.

Rik <rik5>
Project Administrator
Thu 27 Oct 2016 04:09:54 PM UTC, comment #1:

Yeah, this is confusing to me as well. I remembered that I had submitted a fix for this a while ago.

Turns out that single-quoted strings and double-quoted strings are processed differently in Octave regexp functions. There are certain escape sequences that are handled only when the pattern string is a single-quoted string.

These include

  • \b means a literal backspace character (while it means word boundary in PCRE syntax)
  • \< \> mean word boundaries
  • \oNNN means a specific octal character

So as a workaround, if you use single quotes, then the angle-bracket word boundary anchors will work. Or use the PCRE word boundary anchor which is just \b .

Anyone else care to comment on the reason for relegating these certain escapes to single quoted strings only?

Mike Miller <mtmiller>
Project Administrator
Thu 27 Oct 2016 01:43:01 AM UTC, original submission:

The following two expressions should give the same result, but they don't: the second is incorrect

Francesco Potortì <pot>

 

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

Attach File(s):
   
   
Comment:
   

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 mtmiller (Posted a comment)
  • -unavailable- added by pot (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 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 04 Nov 2016 03:19:54 PM UTCrik5StatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
      Release4.0.3=>dev
    Thu 27 Oct 2016 04:12:25 PM UTCrik5StatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1