how to match patterns begining with : and endsing with space
Afficher commentaires plus anciens
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 commentaires
Azzi Abdelmalek
le 3 Sep 2013
Modifié(e) : Azzi Abdelmalek
le 3 Sep 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
le 3 Sep 2013
Réponse acceptée
Plus de réponses (2)
Azzi Abdelmalek
le 3 Sep 2013
Modifié(e) : Azzi Abdelmalek
le 3 Sep 2013
regexp(str,'\d+(\s)?\d','match')
2 commentaires
Jane
le 3 Sep 2013
Azzi Abdelmalek
le 3 Sep 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
le 3 Sep 2013
regexp(str, '(?<=:)[^ :]+', 'match')
3 commentaires
Jane
le 3 Sep 2013
Walter Roberson
le 3 Sep 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
le 3 Sep 2013
Catégories
En savoir plus sur Share and Distribute Software dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!