ruby, using regex to find something in between two strings

后端 未结 4 478
醉话见心
醉话见心 2021-02-04 06:37

Using Ruby + regex, given:

starting-middle+31313131313@mysite.com

I want to obtain just: 31313131313

ie, what is between

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-04 07:20

    Between 1st + and 1st @:

    to[/\+(.*?)@/,1]
    

    Between 1st + and last @:

    to[/\+(.*)@/,1]
    

    Between last + and last @:

    to[/.*\+(.*)@/,1]
    

    Between last + and 1st @:

    to[/.*\+(.*?)@/,1]
    

提交回复
热议问题