[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
regexp question
From: |
PhilipNienhuis |
Subject: |
regexp question |
Date: |
Mon, 5 Dec 2011 13:40:05 -0800 (PST) |
I need to check if a string contains one or more sequences of exactly two
identical consecutive characters.
So I figured I could do (in Octave-3.4.3 MinGW), e.g.:
octave:1> tststr = 'baaaaa baab'
tststr = baaaaa baab
octave:2> regexp (tststr, "a{2}")
but the result is:
ans =
2 4 9
which -depending on perception- may be right but intuitively is not what I
expected (uhm, hoped).
I'd expect the first sequence of five consecutive "a"s to be indexed only
with a pattern of "a{5}" but obviously I'm wrong.
Now, the "aaaaa" substring actually contains 4 "aa" sequences, so regexp's
choice is at least a bit arbitrary; I couldn't find in the docs that regexp
only returns non-overlapping substring patterns.
IMO strfind() does this more consistently:
octave:12> strfind (tststr, 'aa')
ans =
2 3 4 5 9
Anyway:
Q1: Just to be sure: IS this the way regexp() is supposed to work?
Q2: Of course: how can I get together what I'm after? i.e., to find only the
position of the one "aa" substring in tststr starting at position 9?
Thanks,
Philip
--
View this message in context:
http://octave.1599824.n4.nabble.com/regexp-question-tp4162260p4162260.html
Sent from the Octave - General mailing list archive at Nabble.com.
- regexp question,
PhilipNienhuis <=
Re: regexp question, Sergei Steshenko, 2011/12/05