how to read text files using regular expressions

8 次查看(过去 30 天)
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:

采纳的回答

Walter Roberson
Walter Roberson 2017-7-12
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 个)

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by