Regex: Check if string contains at least one digit

后端 未结 9 2083
盖世英雄少女心
盖世英雄少女心 2020-12-09 07:40

I have got a text string like this:

test1test

I want to check if it contains at least one digit using a regex.

What would this reg

9条回答
  •  时光取名叫无心
    2020-12-09 08:12

    The regular expression you are looking for is simply this:

    [0-9]
    

    You do not mention what language you are using. If your regular expression evaluator forces REs to be anchored, you need this:

    .*[0-9].*
    

    Some RE engines (modern ones!) also allow you to write the first as \d (mnemonically: digit) and the second would then become .*\d.*.

提交回复
热议问题