Finding phrase *not* followed by preceding character

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Thomas Schremser

Finding phrase *not* followed by preceding character

Post by Thomas Schremser »

Hi everybody!

I've got files which contain text like

Code: Select all

* ON *
where * stands for an arbitrary character. There are certain occurences of this text at which the left character is the same as the right one. These occurences are easily found with (using POSIX)

Code: Select all

(.) ON \1
My problem is that I want to find occurences where the characters are different. I've tried

Code: Select all

(.) ON ^\1
which doesn't find anything and

Code: Select all

(.) ON [^\1]
which finds all occurences regardless if the characters are different or the same. Does anybody have an idea how to resolve this?

TIA
User avatar
meisn
Posts: 11
Joined: Wed Oct 18, 2006 6:25 pm
Location: Germany
Contact:

Post by meisn »

Hi Thomas,

have you tried the same procedure with wild edit?

(.) ON \1

will work with it.

The thing is, if I understand this correctly, that the POSIX Syntax (or NFAs in general) doesn't support back-references in the search string. Maybe this is related to the backtracking mechanism of the engine.

Please give it a try with the WildEdit program.

Regards,

Meisn
User avatar
meisn
Posts: 11
Joined: Wed Oct 18, 2006 6:25 pm
Location: Germany
Contact:

Sorry

Post by meisn »

Hi,

sorry Thomas but there was a slightly misunderstanding when I had posted my first answer.

My suggestion will only find preceding or equal matches like A ON A etc.

Your question was to find the opposite which is more difficult to do.

I will try to think about it and will post my results (if I will find something :wink: )

Sorry again

Meisn
User avatar
meisn
Posts: 11
Joined: Wed Oct 18, 2006 6:25 pm
Location: Germany
Contact:

Maybe this works

Post by meisn »

Hello Thomas,

I've tried to find something out and this solution works with the WildEdit:

(.) ON (?!\1)[A-Z]+

It uses the Negative Lookahead to prevent the regex from matching equal characters and catch the character afterwards.

This is:

1. (.) any charcter
2. (?!\1) the negative lookaround, which points to the non-equal charcter
3. [A-Z]+ any character which occurs one or more times

I had tried it on this little example, the green marked lines are matches:

A ON A
B ON B
B ON C
A ON C

A ON A

Please let me know if this solves your problem.
Thomas Schremser

Re: Maybe this works

Post by Thomas Schremser »

Hi meisn!
meisn wrote: I've tried to find something out and this solution works with the WildEdit:

(.) ON (?!\1)[A-Z]+
Thank you very much. This is exactly what I was looking for.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Re: Maybe this works

Post by ben_josephs »

meisn wrote:(.) ON (?!\1)[A-Z]+
Or just
(.) ON (?!\1).
Post Reply