Matching character NOT followed by another

General questions about using TextPad

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

Post Reply
User avatar
SteveH
Posts: 327
Joined: Thu Apr 03, 2003 11:37 am
Location: Edinburgh, Scotland
Contact:

Matching character NOT followed by another

Post by SteveH »

This isn't a query related specifically to the regular expression engine in TextPad - I suspect it can't be done in TextPad.

Is there anyway to stop a regular expression match ending either at a specific character or at the end of a line?

Code: Select all

- Some Text (19/09/10)
- More Text @home @today
For example in the first case I would wish to capture the whole line but in the second stop the match before the first '@' character.

I reckon this requires some form of negative lookahead (?=@) but making this lazy and running to the end of the line without an @ present is testing my tired brain.
Running TextPad 5.4 on Windows XP SP3 and on OS X 10.7 under VMWare or Crossover.
ben_josephs
Posts: 2459
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

^[^@]+
User avatar
SteveH
Posts: 327
Joined: Thu Apr 03, 2003 11:37 am
Location: Edinburgh, Scotland
Contact:

Post by SteveH »

That works beautifully in TextPad which is a great starting point. In the application I am using it starts on a new line and then will match over multiple lines until an @ character which may be some lines down.

In my example it would match from '- Some text' through to the @.

I think I always need to limit the search to the end of a line and I'll have a think about how to do this.
Running TextPad 5.4 on Windows XP SP3 and on OS X 10.7 under VMWare or Crossover.
Post Reply