Regex: match only letters WITH numbers

前端 未结 4 2137
梦谈多话
梦谈多话 2021-02-13 22:02

How can I create a regex expression that will match only letters with numbers?

I\'ve tried something like (?>[A-z]+)([a-z0-9]+).

4条回答
  •  囚心锁ツ
    2021-02-13 22:24

    Other answers are incorrect, and will allow any string that only contains letters, numbers or both. My expression will specifically exclude strings that consist only of letters or only of numbers.

    [A-Za-z0-9]*([a-zA-Z]+[0-9]+|[0-9]+[a-zA-Z]+)
    

    Any number of letters and numbers, followed by at least one letter followed by a number or at least one number followed by a letter.

    There is possibly a simpler way of doing this, however. Mine seems long winded. Maybe it's not. Anyone care to pitch in? :P

提交回复
热议问题