RegexWars
Tier 2 · Archmagereplace

Thousands

Insert commas as thousands separators: 1234567 becomes 1,234,567.

You are matching positions, not characters — every point that has a multiple of three digits left after it. Nothing is consumed, so nothing is deleted. The obvious guard for "not the very start" is \B, and it is wrong. \B means "not a word boundary", which is true between two letters and between two digits — but also between a letter and a digit, because both are word characters. So item100 becomes item,100. What you actually want to say is that a digit must precede the position, which is a different question and needs a lookbehind to ask it.

Your pattern0 chars · par 27
//
Flags
Start typing — tests run as you go.0 of 6 visible tests passing
Test cases
  • 1234567→ "1,234,567"
  • 1000→ "1,000"
  • 100→ "100"
  • 12→ "12"
  • 1234→ "1,234"
  • item100→ "item100"

    a word ending in digits is not a number to group

+ 6 hidden tests, checked when you submit. They are what stops a pattern that only fits the examples above.