how to read text files using regular expressions
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Li Xue
am 12 Jul. 2017
Beantwortet: Walter Roberson
am 12 Jul. 2017
What is a fast way to read lines that matches some regular expressions from a text file? For example, read only the lines starting with integer, and split this line by spaces into a vector. I would like to use textscan, because it is very fast.
An example file looks like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165954/image.png)
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 12 Jul. 2017
textscan is not able process regular expressions.
You can read the entire file in at one time using fileread, into a string. You can use regexp or regexprep to select portions of the string, for which you will probably need to use the options 'lineanchors' and 'dotexceptnewline'. You can then enter break the remaining up using text processing or you can pass the resulting string as the first parameter to textscan replacing the fid parameter.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!