How to return the substring of a string between two strings in Ruby?

后端 未结 3 1933
梦如初夏
梦如初夏 2020-12-08 04:22

How would I return the string between two string markers of a string in Ruby?

For example I have:

  • input_string
  • str1_marker
3条回答
  •  情歌与酒
    2020-12-08 04:33

    Just split it twice and get the string between the markers:

    input_string.split("str1_markerstring").last.split("str2_markerstring").first
    

提交回复
热议问题