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

Re: Searching for >> not >>>

On 14 Feb in article <9e042a4258.fjgraute@xxxxxxxxx>,
   Fred Graute <fjgraute@xxxxxxxxx> wrote:
> In message <00eca61f-7791-7ee8-17b4-079e7e35e5fa@xxxxxxxxxxx>
>           Steve Drain <steve@xxxxxxxxxxx> wrote:

> > On 14/02/2020 09:54, Martin wrote:
> > > I am sure this should be simple ... but how do I search for
> > > instances of ">>" but I do not want ">>>" to be included?
> > > 
> > > Everything I have tried includes instances of the two
> > > characters, even if they were preceeded by the third!
> > 
> > In a simple test this worked: ">>"~">"

That was my first thought ...

> Yes, that's what came to my mind first too, but it doesn't do what
> I think Martin is after. Which is to match ">>" on its own not as
> part of ">>>". The above expression won't match the first two ">"
> but it will match the last two.

... but that was not what I wanted.

> If that is indeed what Martin wants then it's actually quite a
> tricky one to get right. 

Correct - and I feared it might be tricky...
> The best I've come up with so far is:

>  < | ( ~">" .) @0 ">>" ~">"

> This breaks down into:

>  < | (~">" .) if at start-of-line, or if first character isn't ">"
>               then match it (to advance search pointer)

>  @0           actual match starts here, so preceding not coloured
>               in LoF

>  ">>"         literal string to match

>  ~">"         next character should not be ">" for match to succeed

Yes, I can confirm that does exactly what I want. I would never have
got to that solution! I can simplify it slightly because they cannot
be at the start of a line.

For the interested, this is a real situation: those familiar with
BASIC will know the subtle and dangerous difference between using
">>" to shift and ">>>", and I wanted to list all the doubles to
check if they should be triple. (ie arithmetic shifts which should be

Many thanks to Fred, and to all those who tried to find a solution to
my 'simple' problem!


Martin Avison      using a TiMachine running RISC OS 5
                   and the Pluto mail and newsreader