RegEx match exactly 4 digits

Let’s see what the regex /^([SW])\w+([0-9]{4})$/ match

  1. Start with S or W since character class is used
  2. One or more alphanumeric character or underscore(\w = [a-zA-Z0-9_])
  3. Four digits

This match more than just SW0001.

Use the below regex.

/^SW\d{4}$/

This regex will match string that starts with SW followed by exactly four digits.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)