Suppose I have a array of strings like this:
arr = ["\n<start>\n<exposition> <conflict> <escape> <conclusion>\t;\n",
"\n<exposition>\n<bad-guy> <insane-plan>\t;\n",
"\n<conflict>\n<friendly-meeting> <female-interest> <danger>\t;\n"]
I want to extract every string in the array, split it using \n as the delimiter, then put it back to an array like this:
newArr = ["<start>",
"<exposition> <conflict> <escape> <conclusion>",
"<exposition>",
"<bad-guy> <insane-plan>",
"<conflict>",
"<friendly-meeting> <female-interest> <danger>"]
I'm new to Ruby I tried to use for loop to iterate the array but it seems will eliminate all the Unix line ending then I have no delimiters to split the strings, and in the strings in arr they also have couple of extra characters \t; to remove.
arr.map { |s| s.scan(/\n(\<.*?\>)\n/) + s.scan(/(\<.*\>)\t\;\n/) }.flattenscan()..... could you explain that to me?scan()is grabbing characters according to your specification. If you're unfamiliar with regex (sorry if you are) check out: regexone.com as a starter.["<a;b>;<c>;\n<d>;\t<e>"]?