Extracting numbers from non-formatted text

1 visualizzazione (ultimi 30 giorni)
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 ?

Risposta accettata

Ameer Hamza
Ameer Hamza il 17 Mag 2020
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'}

Più risposte (0)

Categorie

Scopri di più su Text Analytics Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by