I'm trying to capture comment block in a string (char array). Regular expression '%.*(\n|$)' captures string from % to the end of the line.
regexp(sprintf(' %%this is a comment'),'%.*(\n|$)','match')
ans =
cell
'% this is a comment'
However, what I want to do is to capture multiple incidence of comment blocks in a char array. The above expression only captures the first one, failing to match '% and this'.
regexp(sprintf(' %%this is a comment\n %%and this\n'),'%.*(\n|$)','match')
ans =
cell
'% this is a comment…'
Could somebody help me about this?
2 Comments
Direct link to this comment
https://la.mathworks.com/matlabcentral/answers/294295-help-to-solve-a-regexp-problem#comment_378099
Direct link to this comment
https://la.mathworks.com/matlabcentral/answers/294295-help-to-solve-a-regexp-problem#comment_378099
Direct link to this comment
https://la.mathworks.com/matlabcentral/answers/294295-help-to-solve-a-regexp-problem#comment_378106
Direct link to this comment
https://la.mathworks.com/matlabcentral/answers/294295-help-to-solve-a-regexp-problem#comment_378106
Sign in to comment.