Regex in KornShell

前端 未结 5 2084
忘掉有多难
忘掉有多难 2020-12-31 13:48

I am trying to check whether a variable is exactly two numbers but I can not seem to figure it out.

How do you do check regular expressions (regex) in KornShell (ksh

5条回答
  •  盖世英雄少女心
    2020-12-31 14:44

    Where I come from, this is more likely to validate numeric months:

    if (( $month >= 1 && $month <= 12 ))
    

    or

    [[ $month =~ ^([1-9]|1[012])$ ]]
    

    or to include a leading zero for single-digit months:

    [[ $month =~ ^(0[1-9]|1[012])$ ]]
    

提交回复
热议问题