RegEx match exactly 4 digits

后端 未结 2 995
眼角桃花
眼角桃花 2021-01-04 00:10

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

This pattern should match a string like SW0001 with SW-Prefix an

2条回答
  •  忘掉有多难
    2021-01-04 00:43

    in regex,

    • ^ means you want to match the start of the string
    • $ means you want to match the end of the string

    so if you want to match "SW" + exactly 4 digits you need

    ^SW[0-9]{4}$ 
    

提交回复
热议问题