• 5-1-3-shell:字符串处理基础--expr篇


    长度

    str='this is a test str.'
    
    expr length "${str}" 
    结果: "19"
    
    expr "${str}" : '.*'
    结果: "19"

    拼接

    ??

    截取--索引

    str='this is a test str.'
    expr substr "${str}" 2 6
    
    结果: "his is"

    截取--子字符串

    str='this is a test str.'
    expr "${str}" : '(.*)s is(.*)'
    
    结果: "thi"

    位置

    str='this is a test str.'
    
    expr "${str}" : 'thi.'
    结果: "4"
    
    expr "${str}" : '.*is*'
    结果: "7"

    模式匹配

    str='this is a test str.'
    
    #开头匹配截取
    expr "${str}" : 'this(.*)'
    结果:" is a test str."
    
    # 截取匹配后置
    expr "${str}" : '.*is(.*)'
    结果:" a test str."
    
    # 截取匹配前置
    expr "${str}" : '(.*)test*'
    结果:"this is a "
  • 相关阅读:
    Python2.7-math, cmath
    Python2.7-pprint
    Python2.7-copy
    Python2.7-weakref
    Python2.7-Queue
    Python2.7-sched
    Python2.7-array
    Python2.7-bisect
    搜索专题:Balloons
    【洛谷P4460】解锁屏幕【状压dp】
  • 原文地址:https://www.cnblogs.com/lamp-lrh/p/14673924.html
Copyright © 2020-2023  润新知