Search code examples
regexmatlabstring-parsing

Split alternating string number appearence


Sorry for my question, I am new in regular expressions, I am looking a clever way to split strings of this pattern A007B001C017D021E041 into A, 007, B, 001, C, 017, D, 021, E, 041. In other words, the input is a [string][threeDigits] pattern repeated five times and the output is a separation [string],[threeDigits] for every repetition. Could you please give a suggestions using regular expressions of a matlab build-in function?

Thanks.


Solution

  • A possible solution:

    tokens = regexp(str, '([a-zA-z])(\d\d\d)', 'tokens');
    array = [tokens{:}];