Quote:
Originally Posted by greenskye
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('§',',')