Non sono sicuro Comprendo bene le vostre esigenze, ma penso che si potrebbe usare confini di parola come:
\b([1-9]\d*[.,]\d{2})\b
Al fine di non corrispondere le date, è possibile utilizzare:
(?:^|[^.,\d])(\d+[,.]\d\d)(?:[^.,\d]|$)
spiegazione:
The regular expression:
(?-imsx:(?:^|[^.,\d])(\d+[,.]\d\d)(?:[^.,\d]|$))
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with^and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[^.,\d] any character except: '.', ',', digits
(0-9)
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
----------------------------------------------------------------------
[,.] any character of: ',', '.'
----------------------------------------------------------------------
\d digits (0-9)
----------------------------------------------------------------------
\d digits (0-9)
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
[^.,\d] any character except: '.', ',', digits
(0-9)
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
$ before an optional \n, and the end of
the string
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
Sono un po 'confuso. Quale espressione regolare stai usando? Primo o secondo. E vuoi solo trovare l'ultimo risultato, giusto? –
Nota che '[a | b]' è 'a' o' | 'o' b'. Negli elenchi di caratteri, '|' è * non * un separatore di alternative. Quindi '[.,]' Dovrebbe essere quello che vuoi. Ma per quanto posso dire, la seconda regexp dovrebbe funzionare. –
Io uso entrambi ... Ho priceFormats.add ("([1-9] [0-9] * [\\. |,] [0-9] {2}) [^ \\. \\ d ] ") (*).; e priceFormats.add ("^ ([1-9] [0-9] * [\\. |,] [0-9] {2}) $"); ... è un elenco di formati di prezzo e quindi un ciclo per cui si applica (int i = 0; i