help-octave
[Top][All Lists]
Advanced

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

Re: regexp question


From: Sergei Steshenko
Subject: Re: regexp question
Date: Tue, 6 Dec 2011 10:27:07 -0800 (PST)




----- Original Message -----
> From: Philip Nienhuis <address@hidden>
> To: William Krekeler <address@hidden>
> Cc: "address@hidden" <address@hidden>; address@hidden
> Sent: Tuesday, December 6, 2011 7:52 PM
> Subject: Re: regexp question
> 
> Sergei, Wiliam,
> 
> 2 answers in one post:
> 
> Sergei Steshenko wrote:
>>  I guess you need 'aa' surrounded by not 'a'. Octave uses 
> PCRE; I am not familiar with nuances of Octave PCRE usage; in Perl I would 
> write 
> the regular expression this way:
>> 
>>  [^a]aa[^a]
>> 
>>  and if/when it matches, it returns pointer to the character preceding the 
> 'aa' substring, i.e. in case of 'baab' it should return pointer 
> to the first 'b'.
> 
> Thanks, Sergei. I already tried this and found it'll work, but unfortunately 
> not in a more complicated situation:
> 
> octave:35> tststr3 = 'aa aaaaa baa'     ## Patterns at start & 
> end
> tststr3 = aa aaaaa baa
> octave:36> regexp (tststr3, "[^a]aa[^a]")
> ans = [](1x0)                           ## Hey......
> 
> but
> octave:41> tststr4 = ' aa aaaaa baa '   ## Note spaces at start and 
> end
> tststr4 =  aa aaaaa baa
> octave:42> regexp (tststr4, "[^a]aa[^a]")
> ans =
>     1   11
> 
> ... so it doesn't catch the pattern at start and end of line.
> 
[snip]

I still suggest the Perl regular expressions tutorials/documentation I gave 
links to.

Straightforwardly the regular expression can be extended to (in Perl syntax) :

(^|[^a])(aa)([^a]|$)
#  $1    $2    $3
.

Not inside character class '^' means line beginning, and '$' means line end.

In Perl terms the 'aa' part you are interest in is in $2.

Regards,
  Sergei.


reply via email to

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