I have a cell array 3×1 like this:
name1 = text1
name2 = text2
name3 = text3
and I want to parse it into separate cells 1×2, for example name1 , text1. In future I want to treat text1 as a string to compare with other strings. How can I do it? I am trying with regexp and tokens, but I cannot write a proper formula for that, if someone can help me with it please, I will be grateful!
This code
produces the outcome
Note that the whitespace around the equal sign is preserved. You can modify this behaviour by adjusting the regular expression, e.g. also try
'([^\s]+) *= *([^\s]+)'givingEdit: Based on the comments by user1578163.
Matlab also supports less-greedy quantifiers. For example, the regexp
'(.*?) *= *(.*)'(note the question mark after the asterisk) works, if the text contains spaces. It will transforminto