Replacing character between square brackets

2 ビュー (過去 30 日間)
Muhammad Rahil Rafiq
Muhammad Rahil Rafiq 2020 年 3 月 2 日
A={'[ABC; DEF];[GHI; JKH];'; '[ZBC; YEF];[XHI; UKH];'}
I need to replace ";" only which are appearing within sqare brackets with "^"

採用された回答

Stephen23
Stephen23 2020 年 3 月 2 日
編集済み: Stephen23 2020 年 3 月 2 日
>> A = {'[ABC; DEF];[GHI; JKH];'; '[ZBC; YEF];[XHI; UKH];'}
A =
'[ABC; DEF];[GHI; JKH];'
'[ZBC; YEF];[XHI; UKH];'
>> B = regexprep(A,'(\[[^\]]+);([^\]]+\])','$1^$2')
B =
'[ABC^ DEF];[GHI^ JKH];'
'[ZBC^ YEF];[XHI^ UKH];'
or perhaps:
>> B = regexprep(A,'(?<!\]);(?!\[)','^')
B =
'[ABC^ DEF];[GHI^ JKH];'
'[ZBC^ YEF];[XHI^ UKH];'
  6 件のコメント
Stephen23
Stephen23 2020 年 3 月 2 日
>> A = {'[ABC; DEF; LMN];[GHI; JKH; OPQ; RST];'; '[ZBC; YEF; UVW; XYY; DFF; TRR];[XHI; UKH];'}
A =
'[ABC; DEF; LMN];[GHI; JKH; OPQ; RST];'
'[ZBC; YEF; UVW; XYY; DFF; TRR];[XHI; UKH];'
>> B = regexprep(A,'(\[[^\]]+\])','${strrep($1,'';'',''^'')}')
B =
'[ABC^ DEF^ LMN];[GHI^ JKH^ OPQ^ RST];'
'[ZBC^ YEF^ UVW^ XYY^ DFF^ TRR];[XHI^ UKH];'
Muhammad Rahil Rafiq
Muhammad Rahil Rafiq 2020 年 3 月 2 日
Thanks again!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBoard games についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by