How do I extract the last Time value from a .txt file using regexp?
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
I have a few hundred files that has header information. An example is as follows:
Measurement: ENERGY
Date: 02/31/2019,02/31/2018
Time: 10:34:51.49,15:21:39.24
Temperature (C): 32.82,8.88,-10.07,32.66,8.94,-10.07
TEC Silicon Temperature (C): 9.90,9.88
Battery Voltage: 7.52,7.41
I want to be able to extract the second time values from each of the files and I have the following extract of code:
filetext = fileread(NameIn);
expr = '(?s)\sTime:\s\d+:\d\d\:\d\d\.+\d+\,(?P<myfield>)+';
time = regexp(filetext, expr, 'once','match')
But, the output is a 0x0 empty char array. What am I doing wrong? :(
Antworten (1)
Elias Gule
am 6 Mär. 2018
For this particular case, the following 'regex' seems to be working:
expr = '(?<=Time\s*:\s*(\d{2}:\d{2}:\d{2}\.\d{2},\d{2}:\d{2}:))(?<your_field>(.*))';
time = regexp(txt, expr, 'names','dotexceptnewline');
When a match is found this will return a struct array with a field named: "your_field".
2 Kommentare
BrainOnLunchBreak
am 6 Mär. 2018
Elias Gule
am 9 Mär. 2018
ok. try the attached code and text file.
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!