[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #47403] 'strsplit' function doesn't work with
From: |
Luis Mendo |
Subject: |
[Octave-bug-tracker] [bug #47403] 'strsplit' function doesn't work with delimiter '+' |
Date: |
Mon, 14 Mar 2016 01:29:34 +0000 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 |
URL:
<http://savannah.gnu.org/bugs/?47403>
Summary: 'strsplit' function doesn't work with delimiter '+'
Project: GNU Octave
Submitted by: lmendo
Submitted on: lun 14 mar 2016 01:29:33 GMT
Category: Octave Function
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Incorrect Result
Status: None
Assigned to: None
Originator Name: Luis Mendo
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: 4.0.0
Operating System: Any
_______________________________________________________
Details:
The following produces an error
strsplit('a+bb++ccd+a++', '+')
instead of the correct result, which is
ans =
{
[1,1] = a
[1,2] = bb
[1,3] = ccd
[1,4] = a
[1,5] =
}
The problem seems to be that line 199 of 'strsplit.m'
## Escape characters which have a special meaning in regexp.
del = regexprep (del, '([{}()[\]^$.*?|\\])', '\\$1');
doesn't escape '+' (it does escape other characters).
The solution is simply to add '\+' (escaped) to the regexp in that line, so
that '+' also gets escaped:
## Escape characters which have a special meaning in regexp.
del = regexprep (del, '([{}()[\]^$.*?|\\\+])', '\\$1');
I attach the modified file. It seems to work correctly, also with the
'CollapseDelimiters' option:
>> strsplit_modified('a+bb++ccd+a++', '+', 'CollapseDelimiters', false)
ans =
{
[1,1] = a
[1,2] = bb
[1,3] =
[1,4] = ccd
[1,5] = a
[1,6] =
[1,7] =
}
_______________________________________________________
File Attachments:
-------------------------------------------------------
Date: lun 14 mar 2016 01:29:33 GMT Name: strsplit_modified.m Size: 11kB
By: lmendo
<http://savannah.gnu.org/bugs/download.php?file_id=36627>
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?47403>
_______________________________________________
Mensaje enviado vía/por Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #47403] 'strsplit' function doesn't work with delimiter '+',
Luis Mendo <=