How to match from 2 square brackets till end using regular expression

17 ビュー (過去 30 日間)
Farook Sadarudeen
Farook Sadarudeen 2017 年 12 月 19 日
コメント済み: Farook Sadarudeen 2017 年 12 月 19 日
I want to replace a string starting from 2 square brackets till end of the brackets. For example: s1 = '{[1,2],[3,4],[[5,6],[7,8]]}'; s2 = '[9,10],[11,12]'; Need to place from [5,6],[7,8]] with [9,10],[11,12] expected result: s3 = '{[1,2],[3,4],[[9,10],[11,12]]}' Anyone can support to build the regular expression?

採用された回答

KL
KL 2017 年 12 月 19 日
Something like this,
s1 = '{[1,2],[3,4],[[5,6],[7,8]]}';
s2 = '[9,10],[11,12]';
s3 = regexprep(s1,'(?<=\[)(\[)[^)]*(\])(?=\])',s2)
s3 =
'{[1,2],[3,4],[[9,10],[11,12]]}'

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by