Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
(?=\b\d|\G)\d+?(?=(?:\d{3})+\b)
/
g

Description

Use substitution to put commas in all numbers to separate the thousands. ie: 12345678 → 12,345,678.

The number could be in a sentence, and there may be more than one number in the sentence.

Submitted by anonymous - 2 months ago