Page 1 of 1

Matching character NOT followed by another

Posted: Fri Mar 19, 2010 12:10 pm
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.

Posted: Fri Mar 19, 2010 12:21 pm
by ben_josephs
^[^@]+

Posted: Fri Mar 19, 2010 12:45 pm
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.