octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

regexp: returning '0' in place of 'empty' for no match ?


From: CdeMills
Subject: regexp: returning '0' in place of 'empty' for no match ?
Date: Fri, 19 Nov 2010 02:09:09 -0800 (PST)

Hello,

Problem: scan a number of strings for some pattern using cellfun. In its
simplest form, regexp() returns an integer if there is a match, or 'empty'
if there is no. So, to construct an index of the matching strings, the
construct is rather long:

find(~cellfun('isempty', cellfun(@(x) regexp(x, my_pattern), my_strings,
'UniformOutput', false)))

A bit of explanation: an iteration is performed on 'my_strings', and
UniformOutput must be set to false, otherwise the innermost cellfun will
stop in case regexp returns empty values. The result is a cell array, on
which a second iteration is performed to detect non-empty ones.

The construct would be simpler if regexp return value was 0 for a no-match
-- such value can't be used as an index. Would be possible to either change
regexp interface, which contains a risk of breaking things, either add some
flag to force a non-empty return value ?

Regards

Pascal
-- 
View this message in context: 
http://octave.1599824.n4.nabble.com/regexp-returning-0-in-place-of-empty-for-no-match-tp3050139p3050139.html
Sent from the Octave - Maintainers mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]