R: removing the last three dots from a string

后端 未结 3 1619
我在风中等你
我在风中等你 2021-01-03 04:49

I have a text data file that I likely will read with readLines. The initial portion of each string contains a lot of gibberish followed by the data I need. Th

3条回答
  •  旧时难觅i
    2021-01-03 05:14

    Reverse the string
    Reverse the pattern you're searching for if necessary - it's not in your case
    Reverse the result

    [haiku-pseudocode]

    a = 'first string of junk... 0.2 0 1' // string to search
    b = 'junk' // pattern to match 
    
    ra = reverseString(a) // now equals '1 0 2.0 ...knuj fo gnirts tsrif'
    rb = reverseString (b) // now equals 'knuj'
    
    // run your regular expression search / replace - search in 'ra' for 'rb'
    // put the result in rResult
    // and then unreverse the result
    // apologies for not knowing the syntax for 'R' regex
    

    [/haiku-pseudocode]

提交回复
热议问题