Replace / Remove Chars between tabs

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
pcbbsuk
Posts: 3
Joined: Tue Feb 19, 2008 9:44 am
Location: London

Replace / Remove Chars between tabs

Post by pcbbsuk »

Hi

I am trying to figure out a regular expersion to replace between tabs and remove the characters between other tabs i.e.

Invoice Date Product ID XMLSource Message
60234 2007/01/25 7876 X125 [c:\xml\file.xml] "Invoice for customer.xyza.value.3433.tyr"

like

XMLSource Message
[c:\xml\file.xml] "Invoice for reference.xyza.value.3433.tyr"

Thank you

pcb
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Please enclose laid-out text in

Code: Select all

[/color][/b]...[b][color=blue][/code ][/color][/b] tags and show exactly where the tabs are, so that we don't have to fish it out from the source of the web page. Like this:
[code]Invoice  Date\tProduct ID\t      XMLSource\tMessage
60234    2007/01/25\t7876     X125   [c:\xml\file.xml]\t"Invoice for customer.xyza.value.3433.tyr"

XMLSource\t                Message
[c:\xml\file.xml]\t"Invoice for reference.xyza.value.3433.tyr"
pcbbsuk wrote:replace between tabs and remove the characters between other tabs
I have no idea what this means.

In some cases the field separator is a tab, in others it's spaces, in yet others it's both. What exactly identifies a field separator? Is it a sequence of tabs and spaces including either one tab or at least two spaces? (This would make identification of empty fields difficult.)

Please explain precisely the rules that determine how the input should be transformed into the output. What determines which fields are included in the output and which aren't? Are 16 spaces always to be inserted before the text Message? And so on...
pcbbsuk
Posts: 3
Joined: Tue Feb 19, 2008 9:44 am
Location: London

Post by pcbbsuk »

Hi Please see code attached:

Code: Select all

Invoice	Date		Product	ID	XMLSource   Message 
60234	2007\01\25	7876	X125	[c:\xml\file.xml]     "Invoice for customer.xyza.value.3433.tyr" 

XMLSource		Message 
[c:\xml\file.xml]	"Invoice for reference.xyza.value.3433.tyr"
All the fields are tab seperated and i would like to remove all the data before the fifth tab i.e. before XMLSource in all of the rows.

is that possibles?

thank you :roll:

pcb
User avatar
Nicholas Jordan
Posts: 124
Joined: Mon Dec 20, 2004 12:33 am
Location: Central Texas ISO Latin-1
Contact:

regular expressions can't count

Post by Nicholas Jordan »

I would not use the contraction can't count, but I saw that from a classical text on compilers by Kenneth C. Louden - giving the explaination that the proof of why not is studied in automa theory under the heading "pumping lemma"

The approach I am trying right this moment in my own program is to wrap the re in a loop that replaces the pattern searched for each iteration - thus the solution to your design challenge may be to look for the pattern you are looking for. ( no difficulty intended here - it is just that looking for tabs to find the n-th tab with a tool that cannot count suggests top-down review )
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

In both the versions you've posted here, your fields are not tab-separated.

But if they are tab-separated in the original, this will do the trick:
Find what: ^([^\t]*\t){4}
Replace with: [nothing]

[X] Regular expression

Replace All
This assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
pcbbsuk
Posts: 3
Joined: Tue Feb 19, 2008 9:44 am
Location: London

this works great

Post by pcbbsuk »

Hi

Thank you very much for your help, this works well..

Is there any good tutorials for the Textpad POSIX regular expression or any general book on POSIX regular would work?

thank you

pcbbs
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

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

A standard reference for regular expressions is

Friedl, Jeffrey E F
Mastering Regular Expressions, 3rd ed
O'Reilly, 2006
ISBN: 0-596-52812-4
http://regex.info/

But 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 TextPad.
Post Reply