Filter löschen
Filter löschen

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

10 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

KL
KL am 19 Dez. 2017
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]]}'

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by