RegEx match exactly 4 digits

asked9 years ago
last updated9 years ago
viewed173.5k times
Up Vote45Down Vote

Ok, i have a regex pattern like this /^([SW])\w+([0-9]{4})$/

This pattern should match a string like SW0001 with SW-Prefix and 4 digits.

I thougth [0-9]{4} would do the job, but it also matches strings with 5 digits and so on.

Any suggestions on how to get this to work to only match strings with SW and 4 digits?