regexp for sentence that contains parentheses

5 ビュー (過去 30 日間)
Henk-Jan Ramaker
Henk-Jan Ramaker 2019 年 6 月 26 日
回答済み: Henk-Jan Ramaker 2019 年 6 月 26 日
I have a *.csv file that I read wih the following command:
filetext = fileread('example_file.csv');
This file contains a header that I would like to read line-by-line. The header contains some lines like:
Experiment name;AFS2_test1
Integration time internal baseline (ms);10.00
To look for the line that matches with the first one ('Experiment name') I do the following:
expr = '[^\n]*Experiment name[^\n]*'
matches = regexp(filetext,expr,'match');
matches =
1×1 cell array
{'Experiment name;AFS2_test1'}
But when I search for the second line ('Integration time (ms)') I get:
expr = '[^\n]*Integration time (ms)[^\n]*'
matches = regexp(filetext,expr,'match')
matches =
0×0 empty cell array
I suspect it has anything to do with the parentheses that enclose the word 'ms' but i'm not sure. Who can help me to define the correct regexp?
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 6 月 26 日
In your pattern use \( and \)

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2019 年 6 月 26 日
Yes, all special regexp characters, [](){}.*+?^$\, have to be escaped with a \, so:
expr = '[^\n]*Integration time \(ms\)[^\n]*'

その他の回答 (1 件)

Henk-Jan Ramaker
Henk-Jan Ramaker 2019 年 6 月 26 日
Thanks a lot for the prompt reply!

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by