Page 1 of 1

Find and Replace with Decimal Numbers

Posted: Wed Dec 02, 2009 5:14 pm
by selfmade
I have a large amount of text in the following format:

EC,090610,170000,01395.60,1

The next to the last element in this comma-delimited series (01395.60) needs to have the leading zero stripped away, and the number needs to be divided by 1,000 to yield 1.3560. The final result should be five digits, one digit before the decimal and four after the decimal.

Is it possible to perform this transformation with a regular expression?

Thank you.

Posted: Wed Dec 02, 2009 6:01 pm
by ben_josephs
Is the first digit always a zero?
Is it acceptable to remove the last digit instead of rounding it properly?
(TextPad's regex search and replace does not support arithmetic, so performing arithmetic, where it is possible at all, can be tedious.)
If so:
Find what: 0([0-9])([0-9]{3})\.([0-9])[0-9]*,([^,]*)$
Replace with: \1.\2\3,\4

[X] Regular expression

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

[X] Use POSIX regular expression syntax

Posted: Wed Dec 02, 2009 6:14 pm
by selfmade
Yes, the first digit is always a zero. Also, the last digit is always a zero, and it can be removed without rounding.

Will your expression work with the default TextPad find/replace feature? It doesn't seem to be working for me.

Posted: Wed Dec 02, 2009 8:33 pm
by selfmade
It works now. Just needed to configure TextPad properly. Thanks!!!!