Sed regexp looking for either whitespace or end of line

前端 未结 3 1971
遇见更好的自我
遇见更好的自我 2021-01-19 12:38

I\'m trying to detect a pattern that has three parts:

  1. A space
  2. Either an \"m\" or a \"t\"
  3. Either a space or the end of a line

I

3条回答
  •  自闭症患者
    2021-01-19 13:16

    Make last space optional:

    sed 's/[ ]\([mt][ ]\?\)$/\1/' input
    

    Posix friendly version:

    sed 's/[ ]\([mt][ ]\{,1\}\)$/\1/' input
    

提交回复
热议问题