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 CenterFile Exchange에서 Text Analytics Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by