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

18 vues (au cours des 30 derniers jours)
Farook Sadarudeen
Farook Sadarudeen le 19 Déc 2017
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?

Réponse acceptée

KL
KL le 19 Déc 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]]}'

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by