494RE: [NTS] Trying to perfect RegExp to match various numbers
- Mar 29, 2011After 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
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.
From: firstname.lastname@example.org [mailto:email@example.com] On Behalf Of mycroftj
Sent: Monday, March 28, 2011 16:10
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!
What I have so far [^\s][\-\+]?\d+,*\d*\.?\d*(?=\s)
there are 0 lines
1 or 2 more.
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 >>