×

Loading...
Ad by
  • 予人玫瑰,手有余香:加拿大新天地工作移民诚聘求职顾问&行业导师!
Ad by
  • 予人玫瑰,手有余香:加拿大新天地工作移民诚聘求职顾问&行业导师!

Help: Unix expert , please coming about regular expression!!

Hi:
Is any expert can tell me how to setup the regular pattern of 11 digits which begins with 3.

The requirement is matching all the 11 digits string like any number between 30,000,000,000 ---39,999,999,999
for example if the input is 41234567890 it will false, but id the input is 31234567890, it will true.

I know one way I can do is: 3[0-9][0-9][0-9] [0-9][0-9][0-9] [0-9][0-9][0-9] [0-9], but the string length is longer than 40 characters which is not acceptable by my application.
any another way to do that use UNIX "extended regular expression"

thanks a lot
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / Help: Unix expert , please coming about regular expression!!
    Hi:
    Is any expert can tell me how to setup the regular pattern of 11 digits which begins with 3.

    The requirement is matching all the 11 digits string like any number between 30,000,000,000 ---39,999,999,999
    for example if the input is 41234567890 it will false, but id the input is 31234567890, it will true.

    I know one way I can do is: 3[0-9][0-9][0-9] [0-9][0-9][0-9] [0-9][0-9][0-9] [0-9], but the string length is longer than 40 characters which is not acceptable by my application.
    any another way to do that use UNIX "extended regular expression"

    thanks a lot
    • try 3[0-9]{10}
      • how to verify?
        I try this before and not get the right result.

        LABSMS0:/ins/sms/conf>echo 21234567890|egrep 3[0-9]{10}
        LABSMS0:/ins/sms/conf>echo 31234567890|egrep 3[0-9]{10}
        LABSMS0:/ins/sms/conf>echo 31234567890|egrep 3[0-9]{10}
        LABSMS0:/ins/sms/conf>


        thanks

        Roger
    • /^3\d*/ or simply /^3\d\d\d\d\d\d\d\d\d\d$/
      • doesn't work, can you tell me know how to verify
        /ins/sms/conf>grep ^3\d\d\d\d\d\d\d\d\d\d$ test
        /ins/sms/conf>grep 3[0-9]{10} test
        /ins/sms/conf>grep 3* test
        31234567890
        23124567899
        300055555768
        ins/sms/conf>grep 3[0-9]{9} test
        /ins/sms/conf>grep 3\d\d\d\d\d\d\d\d\d\d test
        /ins/sms/conf>

        the file name is test

        not get the expect result
        • should that be grep "3[0-9]{10}" test ?
          • does not get the expect result.
            BTW:
            what do you guy to verify the expression?
            some thing I use
            ins> echo 'input string'|egrep 'expression'
            in command line
            or above mathod


            thanks
            • try: /^3\d{10}/
            • It works. see what I got on my system(bourne shell)
              $ echo 31111111111 | egrep "3[0-9]{10}"
              31111111111
              $ echo 31111111111 | egrep '3[0-9]{10}'
              31111111111
              $ echo 311dd111111 | egrep '3[0-9]{10}'
              $ echo "311 11111" | egrep '3[0-9]{10}'
              $ echo "31155511111" | egrep '3[0-9]{10}'
              31155511111
              $ echo "21155511111" | egrep '3[0-9]{10}'
              • which OS do you have, I got Solaris 8.0?
                actually, my scenario is very simple , match a digital string with this pattern, and if match this range, then pass this string to next. otherwise reject.
                the problem is : the vendor of this application did not give the fully document of this , just tell me use the unix expression , it will work.
                I will try it again

                thanks
                • regexp is always the same. It has nothing to do with the OS. In your case, I beleive you need more support from the application vendor.
    • Although there's something called POSIX regular expression, it varies slightly from program to program. The most popular ones are sed, grep and perl, here's how...
      grep: takes one line at a time. "grep '3[0-9]\{10\}' <filename>"
      sed: takes one line at a time. "sed -n '/3[0-9]\{10\}/p' <filename>"
      perl:
      open(IN, "<filename>") or die("cannot open <filename>");
      whiel(<IN>) {
      if($_=~/3\d{10}/) {
      print;
      }
      }

      HTH.
    • Try this one egrep "^3[0-9]{10} | 3[0-9]{10} | 3[0-9]{10}$". 注意,| 前后是space
    • space 也算是字符,若要找以3开头的数字,必须考虑3之前有space 或以3开头的行。grep "3[0-9]{10}” 凡是有3dddddddddd 的字符串都会符合,如23dddddddddd 也符合,所以不对。
    • space 也算是字符,若要找以3开头的数字,必须考虑3之前有space 或以3开头的行。grep "3[0-9]{10}” 凡是有3dddddddddd 的字符串都会符合,如23dddddddddd 也符合,所以不对。