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
There's also Regexp#match
, which returns a MatchData
object, which has all the information you could possibly want.
irb> match = /your username is: (.*)/.match "hello john\nyour username is: jj\nthanks for signing up\n"
#=> #
irb> match.pre_match
#=> "hello john\n"
irb> match.post_match
#=> "\nthanks for signing up\n"
irb> match[0]
#=> "your username is: jj"
irb> match[1]
#=> "jj"