Extracting numbers from non-formatted text

1 回表示 (過去 30 日間)
b
b 2020 年 5 月 17 日
コメント済み: Ameer Hamza 2020 年 5 月 18 日
Hello,
I have a non-formatted text file from which all those numbers need to be extracted which are exactly 10-digit numbers.
Here is the short version of the file :
*()%
kpm c)ompany
1234567890
freight carrier 56789
62345
roadway&s 3456781910
invoice STW7228
5. HRM Ï4
gate \ *+*
3498712338 1 2765114
3790000155678 f ^
4462213459 \
The file is txt and is non-formatted. Formating is not needed. Only value of interest are the 10-digit numbers.
How can this be done ?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 17 日
Try this
str = fileread('test.txt'); % test.txt is the name of text file containing the given text
matches = regexp(str, '\d{10}', 'match')
Result
>> matches
matches =
1×5 cell array
Columns 1 through 4
{'1234567890'} {'3456781910'} {'3498712338'} {'3790000155'}
Column 5
{'4462213459'}
  2 件のコメント
b
b 2020 年 5 月 18 日
Thanks.
Ameer Hamza
Ameer Hamza 2020 年 5 月 18 日
I am glad to be of help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Analytics Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by