![]() |
#46 |
Morlock
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28
Karma: 2587194
Join Date: Oct 2021
Device: Kindle Paperwhite
|
|
![]() |
![]() |
![]() |
#47 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: Feb 2010
Device: none
|
I'm looking for a method to convert numbers that use the european comma separated format (ex. 1.000,95) to the US version (ex 1,000.95)
Is this achievable with regex or via a search function? |
![]() |
![]() |
Advert | |
|
![]() |
#48 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73
Karma: 107742
Join Date: Jul 2021
Device: N/A
|
Assuming all numbers are in european format (no one in US format):
Code:
find: \d[,.\d]{2,}(?![^<>{}]*[>}]) function: def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs): return match.group(0).replace('.', '§').replace(',', '.').replace('§',',') Note: all number with 3 or more positions will be catched (e.g. 1,2, or 1.2). If you want to be more selective, change "{2,} for what you want minus 1, e.g. {4,} if you want to catch starting from 5 positions (1.000 or 12,45) Note: Integers as 100 or 234000 will be catched, but they won't be transformed. Warning : numbers followed by 3 dots will be wrongly transformed : "They were 20..." will give "They were 20,,," It's wise to change them to ellipsis (…) prior to apply the conversion: (\d)\.{3} ==> \1\u2026 Last edited by lomkiri; 04-03-2022 at 01:57 PM. |
![]() |
![]() |
![]() |
#49 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: Feb 2010
Device: none
|
Spoiler:
Thanks so much, it worked great! I ended up using Code:
find 1: (\d{1,3}[.,])+\d{1,}(?![^<>{}]*[>}]) find 2: \$(\d{1,3}[.,])+\d{1,}(?![^<>{}]*[>}]) |
![]() |
![]() |
![]() |
#50 | |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73
Karma: 107742
Join Date: Jul 2021
Device: N/A
|
Mmmh, yes, of course, I forgot this case :-/. Good you thought about it :-)
Quote:
Code:
(\$(?:\d{1,3}[.,])+)(*SKIP)(*F)|(<[^<>]*)(*SKIP)(*F)|(?:\d{1,3}[.,])+\d{1,} Code:
\$?(\d{1,3}[.,])+\d{1,}(?![^<>{}]*[>}]) function: def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs): m = match.group(0) if m[0] == '$': return m else: return m.replace('.', '§').replace(',', '.').replace('§',',') Last edited by lomkiri; 04-04-2022 at 07:10 PM. Reason: adding a regex excluding currency |
|
![]() |
![]() |
Advert | |
|
![]() |
Tags |
conversion, errors, function, ocr, spelling |
Thread Tools | Search this Thread |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
About saved searches and regex | Carpatos | Editor | 22 | 09-30-2020 10:56 PM |
Regex-Functions - getting user input | CalibUser | Editor | 8 | 09-09-2020 04:26 AM |
Difference in Manual Search and Saved Search | phossler | Editor | 4 | 10-04-2015 12:17 PM |
Help - Learning to use Regex Functions | weberr | Editor | 1 | 06-13-2015 01:59 AM |
Limit on length of saved regex? | ElMiko | Sigil | 0 | 06-30-2013 03:32 PM |