- Mar 30, 2011I recall a post by Diodeom in the Clips group, with a bit of razzle-dazzle, that might could do what you want. Perhpas Dio would know what I'm talking about?

I do not remember the topic, but I believe it had to do with sorting a table of numbers, numerically, even though the numbers were left-justified.

Cheers

--- In ntb-scripts@yahoogroups.com, "mycroftj" <mycroftj@...> wrote:

>

> I'm terribly sorry for not being clear. I branched into quite a few directions at once.

>

> The goal was to pad all numbers in a document with spaces or zeros so they would sort correctly.

>

> Instead of writing a clip, I thought it might be done in one mighty regexp replace (777->000777 and 77->000077) but that would involve calculating lengths and taking decimal points into consideration so I don't see how that can be done. OR CAN IT?

>

> I DID want to learn how to pick out just the numbers and Sheri seems to have hit on that perfectly with

> (?:^|\s)\K[\+\-]?[0-9,\.]+(?=\s|$)

> which picks out just the numbers so I can manipulate the selected text in a clip. (Thanks again, Sheri!)

>

> The lines containing FILE were from actual data where as the rest was just a made up assortment of numbers I was experimenting with.

>

> Regexps are one of the most useful things I've stumbled upon in years but SO frustrating. I'll keep trying and I really do appreciate the help from everyone.

>

> Joy

>

>

> --- In ntb-scripts@yahoogroups.com, "John Shotsky" <jshotsky@> wrote:

> >

> > After reading through this several times, I could not determine the actual goal. To get good assistance, you should

> > provide the starting data, the result that is wanted, and the rules you want, as well as identifying any data you don't

> > want.

> >

> > So, is the goal to sort? By numbers only? Padded numbers? Or is the actual data not of interest in your message? It

> > seems that the first part of the message and the last part are not on the same subject to me.

> >

> > Regards,

> > John

> >

> >

> > From: ntb-scripts@yahoogroups.com [mailto:ntb-scripts@yahoogroups.com] On Behalf Of mycroftj

> > Sent: Monday, March 28, 2011 16:10

> > To: ntb-scripts@yahoogroups.com

> > Subject: [NTS] Trying to perfect RegExp to match various numbers

> >

> >

> > My ultimate goal was to create a script that (left) space or zero pads numbers to a fixed length for sorting.

> >

> > Actual data looks something like

> >

> > File 67817 Id.ppt

> > File 691037 20dat.sys

> > File 69870 Lock.doc

> > File 705 56968.mbs

> > File 70537 Jil.xls

> > File 71168 Gas.jpg

> >

> > I then became interested in trying to find a regexp that will match numbers surrounded by BOL, EOL, spaces and tabs with

> > signs, decimal point and commas optional.

> >

> > In the following test data. the numbers starting with 123 should be matched as well as the integers 0, 1 and 2.

> > xxx456 and 456xx should NOT be matched.

> >

> > I have something that mostly works but it also matches x456 and the t2 in hmt2. WHY IS THAT?

> > It also misses 0, 1 and 2 although it does (correctly) pick up -2.

> >

> > I put in the caret because it was not matching numbers at the start of a line. Is that how it's done?

> >

> > Thanks for your help. I ordered the Regular Expressions Cookbook today. Hope it's as good as the reviews say!

> >

> > Joy

> >

> > What I have so far [^\s][\-\+]?\d+,*\d*\.?\d*(?=\s)

> >

> >

> > 12345

> > 12345.678

> > 1234567.90

> > xxx456

> > 456xx

> >

> > xx456,123.34

> > www.45.67.hmt2

> >

> > 12,345

> > -12,345

> > 12,345.

> > +12,345.01

> >

> > 12345

> > +123,45.678

> > 1234567.90

> >

> > there are 0 lines

> > 1 or 2 more.

> >

> > 12345

> > -12345.678

> > 1234567.90

> > xxx456

> > +456xx

> >

> > xx456.34

> > www.45.67.hmt2

> >

> > +12345

> >

> > 12345

> > -12345.678

> > 1234567.90

> > xxx456

> > 456xx

> >

> > there are 0 lines. The zero should match as should the following one and negative two.

> > 1 or -2 more.

> >

> >

> >

> > [Non-text portions of this message have been removed]

> >

> - << Previous post in topic Next post in topic >>