Azzera filtri
Azzera filtri

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

10 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

KL
KL il 19 Dic 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]]}'

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by