how to match patterns begining with : and endsing with space
Mostra commenti meno recenti
Hello,
I've tried to extract data from output files. The data line looks like below
OPT: ATTC_RD:3 ATT2R:0 VGARSH:194 ATT:-10.900 VGA: 9.118 NET: -1.782 METRIC:135764.002 SN:P4105473 CYL: 4319 HD: 0 ONB:master2
I would like to extract the patterns after : and before the space with the following:
a = regexp(tline(6:end),'^(.*):[.*]\s+','match')
But it doesn't work.
Also I have trouble to get the last pattern "master2".
Could someone help me on this ?
Thank you.
Jane
2 Commenti
Azzi Abdelmalek
il 3 Set 2013
Modificato: Azzi Abdelmalek
il 3 Set 2013
str={'OPT: ATTC_RD:3 ATT2R:0 VGARSH:194 ATT:-10.900 VGA: 9.118 NET: -1.782 METRIC:135764.002 SN:P4105473 CYL: 4319 HD: 0 ONB:master2'}
What are you expecting as result?
Jane
il 3 Set 2013
Risposta accettata
Più risposte (2)
Azzi Abdelmalek
il 3 Set 2013
Modificato: Azzi Abdelmalek
il 3 Set 2013
regexp(str,'\d+(\s)?\d','match')
2 Commenti
Jane
il 3 Set 2013
Azzi Abdelmalek
il 3 Set 2013
str={'OPT: ATTC_RD:3 ATT2R:0 VGARSH:194 ATT:-10.900 VGA: 9.118 NET: -1.782 METRIC:135764.002 SN:P4105473 CYL: 4319 HD: 0 ONB:master2'}
out=regexp(str,'[\w-]+(\.)?[\w-]+','match')
celldisp(out)
Walter Roberson
il 3 Set 2013
regexp(str, '(?<=:)[^ :]+', 'match')
3 Commenti
Jane
il 3 Set 2013
Walter Roberson
il 3 Set 2013
Your requirement was for patterns beginning with : and ending with space. A space immediately after the : matches the termination requirement. Perhaps you have not completely specified your problem.
In your substring "OPT: ATTC_RD:3" is "OPT: ATTC_RD" considered as one single label whose associated value is "3", or is "OPT" considered a label whose associated value is "" and "ATTC_RD" is considered a label whose associated value is "3" ? In the substring "VGA: 9.118 NET:" then why is the value asociated with "VGA" not considered to be the empty string, followed by a label that is "9.118 NET" ? Are there any characters that cannot appear in labels? Are there any characters that cannot appear in associated values? Is it the case that when there is a non-numeric value such as "master2" then it is prohibited for there to be any space between the label and the value ?
Jane
il 3 Set 2013
Categorie
Scopri di più su Share and Distribute Software in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!