RegexWars
Tier 3 · Warlockextract

Four Digits, No More

Extract every run of 1 to 4 digits — but never a fragment of a longer number.

A quantifier does not mean "exactly this many and no neighbours". \d{1,4} is perfectly happy to bite 1234 out of the middle of 123456 and then take 56 as a second match. To say "and nothing more on either side" you have to guard both edges: (?<!\d) refuses to start next to a digit, (?!\d) refuses to end next to one. Length limits in regex are always claims about the boundaries, not about the run.

Your pattern1 chars · par 21
//g
Flags
Start typing — tests run as you go.0 of 4 visible tests passing
Test cases
  • order 42 line 7→ ["42", "7"]
  • 1234 and 56→ ["1234", "56"]
  • a1 b22 c333 d4444→ ["1", "22", "333", "4444"]
  • no digits at all→ []

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