Find and Replace with Decimal Numbers

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
selfmade
Posts: 3
Joined: Wed Dec 02, 2009 5:05 pm

Find and Replace with Decimal Numbers

Post 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.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post 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
selfmade
Posts: 3
Joined: Wed Dec 02, 2009 5:05 pm

Post 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.
selfmade
Posts: 3
Joined: Wed Dec 02, 2009 5:05 pm

Post by selfmade »

It works now. Just needed to configure TextPad properly. Thanks!!!!
Post Reply