필터 지우기
필터 지우기

how to read text files using regular expressions

조회 수: 8 (최근 30일)
Li Xue
Li Xue 2017년 7월 12일
답변: Walter Roberson 2017년 7월 12일
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