Regular Expressions

General questions about using TextPad

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

Post Reply
trespasser
Posts: 11
Joined: Wed Jul 02, 2003 6:48 am

Regular Expressions

Post by trespasser »

Hi All,

Wondering if someone can help me with some code for a reg. expression, I have a file that is not very pretty and I am trying to get each new vehicle onto a new line, I have managed to do this to a point but there are a couple that are escpaing, the line looks like this

Line1 - AU A3 5DR SPORTBACK 1.9 TDi EU4,AUDI,08/03/2005,28/10/2005,AUA319
Line2 - 5HDTM 1

What I would like to say is if Line2 does not have a (,) in it, move it onto the line above, so that it looks like -:

AU A3 5DR SPORTBACK 1.9 TDi EU4,AUDI,08/03/2005,28/10/2005,AUA3195HDTM 1

Or it would if this window I am typing in was a little bigger.

Thanks for any help recieved! Phil
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Find what: ^(.*)\n([^,]+)$
Replace with: \1\2

[X] Regular expression
Or, if you want to ensure that the first line contains a comma,
Find what: ^(.*,.*)\n([^,]+)$
Replace with: \1\2

[X] Regular expression
This assumes you are using Posix regular expression syntax:
Configuration | Preferences | Editor

[X] Use POSIX regular expression syntax
trespasser
Posts: 11
Joined: Wed Jul 02, 2003 6:48 am

Post by trespasser »

Thanks for that, it worked brilliantly, can you recomend and good sites for learning about reg. exp. as I like to try and learn as much as I can.

Thanks Phil
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

A standard reference for regular expressions is

Friedl, Jeffrey E F
Mastering Regular Expressions, 2nd ed
O'Reilly, 2002
ISBN: 0596002890
http://regex.info/

There are many tutorials on the web, and you will find recommendations for some of them if you search this forum.

Be aware that the regular expression recogniser used by TextPad is rather weak by the standards of recent tools, so you may get frustrated if you discover a handy trick that doesn't work in this editor.
Post Reply