What's the “ruby way” to parse a string for a single key/value?

前端 未结 4 1166
我在风中等你
我在风中等你 2020-12-31 10:49

I am trying to parse a multi line string and get the rest of the line following a pattern.

text:

hello john
your username is: jj
thanks for signing up

4条回答
  •  灰色年华
    2020-12-31 10:59

    Not sure if it's any more Ruby'ish, but another option:

    >> text = "hello john\nyour username is: jj\nthanks for signing up\n"
    >> text.match(/your username is: (.*)/)[1]
    => "jj"
    

提交回复
热议问题