View Single Post
Old 04-04-2022, 05:55 PM   #50
lomkiri
Groupie
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 172
Karma: 1497966
Join Date: Jul 2021
Device: N/A
Quote:
Originally Posted by greenskye View Post
The updated regex fixed the problem with trailing "." matches
Mmmh, yes, of course, I forgot this case :-/. Good you thought about it :-)

Quote:
I did a replace all with "find 1", and then ran it again with "find 2" to revert any US currencies accidentally caught. Couldn't figure out how to exclude them in first place (kept matching part of the currency number)
This one seems to be ok to exclude groups beginning with $ (and not selecting inside tags) :
Code:
(\$(?:\d{1,3}[.,])+)(*SKIP)(*F)|(<[^<>]*)(*SKIP)(*F)|(?:\d{1,3}[.,])+\d{1,}
Another way would have been to catch the currency in the regex, then it's easy to make the selection inside the function:
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
lomkiri is offline   Reply With Quote