少於 1 分鐘閱讀

方式一

str = “your +example string@ here”

# Between 1st + and 1st @:
str[/\+(.*?)@/,1]

# Between 1st + and last @:
str[/\+(.*)@/,1]

# Between last + and last @:
str[/.*\+(.*)@/,1]

# Between last + and 1st @:
str[/.*\+(.*?)@/,1]

方式二

i = to.index("+")
j = to.index("@")
to[i+1..j-1]

參考

  1. http://stackoverflow.com/questions/4218986/ruby-using-regex-to-find-something-in-between-two-strings

更新時間:

留言