textscan or regex to get numbers from a text message.

3 ビュー (過去 30 日間)
Ajpaezm
Ajpaezm 2019 年 1 月 30 日
編集済み: Walter Roberson 2019 年 1 月 30 日
I have an expression that looks like this:
text = '[API.msg2] Order size 400 is smaller than the minimum required size of 500. {916423570, 388}';
This message can change the values of the numbers in the positions where the 400 and 500 are, I'd like to obtain/capture every number that appear in those positions. I tried doing strcmp or textscan using this, but it wasn't successful.
test = textscan(text, 'Order size %s is smaller than the minimum required size of %s.')
Do you know a way to make this work using textscan or regex? Thanks in advance.

採用された回答

Walter Roberson
Walter Roberson 2019 年 1 月 30 日
編集済み: Walter Roberson 2019 年 1 月 30 日
>> text = '[API.msg2] Order size 400 is smaller than the minimum required size of 500. {916423570, 388}';
>> tf = '[API.msg2] Order size %f is smaller than the minimum required size of %f';
>> sscanf(text,tf)
ans =
400
500
>> textscan(text, tf)
ans =
1×2 cell array
{[400]} {[500]}
>> str2double(regexp(text, '\d{2,}', 'match'))
ans =
400 500 916423570 388

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by