How to match a number between two characters?

8 ビュー (過去 30 日間)
Dario Plüch
Dario Plüch 2019 年 11 月 11 日
編集済み: Matt J 2019 年 11 月 11 日
Hi,
Here is an example from a string: [180] Windabweichung
How can i extract the 180 ?
Thanks.

採用された回答

Matt J
Matt J 2019 年 11 月 11 日
>> str=extractBetween("[180] Windabweichung","[","]")
str =
"180"
  2 件のコメント
Matt J
Matt J 2019 年 11 月 11 日
Dario's comment moved here:
Thanks Matt J,
it works perfect, but in the case for a table of strings as an input.
How can i get another table with extracted values from the input table?
Input=
and output with the same size but with returned numbers.
Thanks
Matt J
Matt J 2019 年 11 月 11 日
編集済み: Matt J 2019 年 11 月 11 日
What you have shown is a string array, not a table. But for string arrays, it should work just the same,
>> s=string({"[180] Windabweichung","[260] mmm"});
>> str=extractBetween(s,"[","]")
str =
1×2 string array
"180" "260"

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

その他の回答 (1 件)

Matt J
Matt J 2019 年 11 月 11 日
編集済み: Matt J 2019 年 11 月 11 日
>> T=regexp('[180] Windabweichung','\[(\d+)\]','tokens'); T{:}
ans =
1×1 cell array
{'180'}

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by