Extract characters at a set position

前端 未结 2 1315
情书的邮戳
情书的邮戳 2021-01-17 15:28

I am trying to find a function that will extract characters at a certain position within a string. For example, I have a long file name with a date in it, and I want to end

相关标签:
2条回答
  • 2021-01-17 15:46

    For example:

    gsub('(.*)([0-9]+{7})[A-Z].*','\\2','LT50420331984221PAC00_B7.tif')
    "1984221"
    

    Here I assume that the date is 7 digits before a capital letter.

    0 讨论(0)
  • 2021-01-17 16:04

    If you know the exact position of the date in your string you can use

    substr('LT50420331984221PAC00_B7.tif', 10, 16)
    
    0 讨论(0)
提交回复
热议问题