I'd like to parse string for two different tags then store each in the database. Let's call these tag1 and tag2. I have a delimeter of sorts, "?#" that is the split between tag1 and tag2.
Suppose
t = "random text blah firsttag?#secondtag more blah"
Goal: tag1 should be "firsttag" and tag2 should be "secondtag" without the preceding or trailing random text. Each should get stored as objects in the database.
I tried something like:
t.split
but it returns
["random text blah firsttag", "secondtag more blah"]
and includes the random text. How can I get the split to stop when it reaches the first space in either direction?
I'd like this to also work if there are multiple tag pairs in the string, for example, if:
m = "random firsttag#?secondtag blah blah 1sttag#?2ndtag blah blah blah"
I'm pretty new to both ruby and rails, so I really appreciate your help on this one!