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
The split command is mindbogglingly useful. It divides a string into an array of substrings, separating on whatever you pass in. If you don't give it any arguments, it splits on whitespace. So if you know the word you're looking for is the fifth "word" (splitting on both spaces and the return character), you can do this:
text = "hello john\nyour username is: jj\nthanks for signing up\n"
match=text.split[5]
..but perhaps that's not sufficiently self-documenting, or you want to allow for multi-word matches. You could do this instead:
midline=text.split("\n")[1]
match=midline.split("username is: ").last
Or perhaps this more terse way:
match=text[/username is: (.*)/,1]