I have a line that looks something like this:
"my name is: andrew"
I would like to parse a string, pull the name out of the string and assign it to a variable. How do I do this with Ruby?
Update:
The line I used as an example was just an example. The lines that I will work with can change formats, so you cannot rely on the colon in the actual example. Here are some examples I work with:
"/nick andrew" # command: nick, value: "andrew" "/join developers" # command: join, value: "developers" "/leave" # command: leave, value: nil
I would like to use some kind of regular expression to solve this problem (since a string can change formats), and not split the string into specific characters or rely on a specific character position number.
source share