Example of string I am working with:
s = "{new {value1 value2 value3}} {old {value2 value1 value1}} {{old school} {value2 value3 value1}}"
The {}’s are affected by spaces, which is why “old school” is surrounded while “new” and “old” are not.
Parsing the first two (new and old) are easily done using s.split[1] to access “new” and s.split[3..5] for the values. The problem comes when “new” or “old” has a space, in this case “old school”. In the database I am accessing, these names with spaces occur randomly.
How can I alter my parsing to account for these occurrences?
You can do it with this one line:
Kind of ugly but works with your example, returns:
You can then parse if further by breaking values into their own objects etc. If you want it as hash, you can get it like this:
This will return: