Regular Expression Problem , Please Help
2 ビュー (過去 30 日間)
古いコメントを表示
I have no idea how to do this ..
str = '[a,b,c,d,e,[f1,f2],g],[u,v,w,[x1,x2],[y1,y2],z]';
Using this code:
regexp(str,'\[.*?(\[.*?\],[.*?\]).*?\]','tokens');
i got an answer like this:
ans =[f1,f2],g],[u,v,w,[x1,x2]
but what I want is like this:
ans = [x1,x2],[y1,y2]
3 件のコメント
Matt Fig
2012 年 9 月 28 日
That doesn't really answer the question. I showed you how to find the answer you requested, then I asked you to give the general form, including the rule for finding what you want. "The string is dynamic" tells me nothing really. Good luck.
回答 (1 件)
Walter Roberson
2012 年 9 月 27 日
Remember, .* will match everything including [ or ] characters. You need to exclude those characters from the search if you are looking for the ] matching a [ .
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!