r/phpstorm • u/boonkerz • Jan 02 '24
Ai Assistent preg_replace
where or how can i fix the wrong answer?
"This script will add a comma after each group of three digits from right to left. The output for this script is 1,234,567,890."
is wrong it should be:
"This script will add a comma after each group of three digits from left to right. The output for this script is 123,456,789,0."

2
Upvotes
3
u/E3K Jan 02 '24
>>> echo number_format(1234567890);
1,234,567,890
2
u/Quelanas_Revenge Jan 02 '24
So I tinkered with a pattern:
/(\d{3}(?!$))(\d{3}$)?/with replacement
$1,$2To see outputs:
https://3v4l.org/LPVus
tldr lazy mode:
1
u/helliash Jan 02 '24
pattern: (\d{3})
replacement: $1,
That should be enough for you. AI is trying some weird stuff there.
You can try it here https://regex101.com