I'm trying to split the string "[test| blah] [foo |bar][test|abc]"
into the following array:
[
["test","blah"]
["foo","bar"]
["test","abc"]
]
But I'm have trouble getting my regular expression right.
Ruby:
@test = '[test| blah] [foo |bar][test|abc]'.split(%r{\s*\]\s*\[\s*})
@test.each_with_index do |test, i|
@test[i] = test.split(%r{\s*\|\s*})
end
I'm not quite there, this returns:
[
[ "[test" , "blah" ]
[ "foo" , "bar" ]
[ "test" , "abc]" ]
]
What would be the correct regular expression to achieve this? It would be great if I could also account for new lines, say: "[test| blah] \n [foo |bar]\n[test|abc]"