How to remove a bracketed number from a cell array while leaving the number in front of it alone

25 ビュー (過去 30 日間)
Hi, I have a cell array called "mycellarray" with the following types of strings in it: 24[13]
The [13] in this case is a reference to a footnote and I want to remove the [13] and just have the number 24 left. How do I use a regular expression to remove "[13]" or any footnote i.e. [3] from the number.
Example of the contents of the cell array
13.4[5]
24[11]
56.99[23]
22[4]
I want to remove all the bracketed values along with the number inside the brackets and just have the double number in front kept in the cell array Thank you for your help.. Bob

採用された回答

Walter Roberson
Walter Roberson 2018 年 11 月 11 日
newstring = regexprep(oldstring, '\[\d+\]', '') ;
  1 件のコメント
Robert Garneau
Robert Garneau 2018 年 11 月 11 日
Thank you so much. There were so many good answers it hard to pick just one. thanks....

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 11 月 11 日
編集済み: madhan ravi 2018 年 11 月 11 日
mycellarray={'24[13]'}
regexprep(mycellarray, '\[(.*?)\]', '$1') %edited after sir Walter's comment
or
A='13.4[5] 24[11] 56.99[23] 22[4]'
A(A=='[') = [];
% Remove any and all right brackets.
A(A==']') = []
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 11 月 11 日
'\[(.*)\]' selects too much if there can be multiple matches in one string. '\[(.*?)\]' would be better.

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

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by