how to match patterns begining with : and endsing with space
Mostrar comentarios más antiguos
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 comentarios
Azzi Abdelmalek
el 3 de Sept. de 2013
Editada: Azzi Abdelmalek
el 3 de Sept. de 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
el 3 de Sept. de 2013
Respuesta aceptada
Más respuestas (2)
Azzi Abdelmalek
el 3 de Sept. de 2013
Editada: Azzi Abdelmalek
el 3 de Sept. de 2013
regexp(str,'\d+(\s)?\d','match')
2 comentarios
Jane
el 3 de Sept. de 2013
Azzi Abdelmalek
el 3 de Sept. de 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
el 3 de Sept. de 2013
regexp(str, '(?<=:)[^ :]+', 'match')
3 comentarios
Jane
el 3 de Sept. de 2013
Walter Roberson
el 3 de Sept. de 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
el 3 de Sept. de 2013
Categorías
Más información sobre Share and Distribute Software en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!