Page 1 of 1

Replace / Remove Chars between tabs

Posted: Tue Feb 19, 2008 10:06 am
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

Posted: Tue Feb 19, 2008 10:49 am
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...

Posted: Tue Feb 19, 2008 2:50 pm
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

regular expressions can't count

Posted: Tue Feb 19, 2008 3:55 pm
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 )

Posted: Tue Feb 19, 2008 4:35 pm
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

this works great

Posted: Tue Feb 19, 2008 5:12 pm
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

Posted: Tue Feb 19, 2008 5:41 pm
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.