MATLAB Answers

How to match a number between two characters?

20 views (last 30 days)
Dario Plüch
Dario Plüch on 11 Nov 2019
Edited: Matt J on 11 Nov 2019
Hi,
Here is an example from a string: [180] Windabweichung
How can i extract the 180 ?
Thanks.

Accepted Answer

Matt J
Matt J on 11 Nov 2019
>> str=extractBetween("[180] Windabweichung","[","]")
str =
"180"
  2 Comments
Matt J
Matt J on 11 Nov 2019
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"

Sign in to comment.

More Answers (1)

Matt J
Matt J on 11 Nov 2019
Edited: Matt J on 11 Nov 2019
>> T=regexp('[180] Windabweichung','\[(\d+)\]','tokens'); T{:}
ans =
1×1 cell array
{'180'}

Community Treasure Hunt

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

Start Hunting!

Translated by