I’m using a regular expression to search blocks of text that look like the following;
MSN_BER (0:31) Observation #1 Rx'd at: (58570.000) Msg. Time: (58568.000) Forward to IMU: true Rcv Date: 2010121 Synch: f0f0 Rep Mode: Replay_Mode State Time: 12:00:00.000 (58571.000) State Position: -1500.0000, -5000.0000, 4100.0000MSN_RAM (0:32) Observation #20 Rx'd at: (58569.000) Msg. Time: (58569.000) Forward to IMU: true Rcv Date: 2010121 Synch: f0f0 Rep Mode: Replay_Mode Fmt: 10 (AIRBORN__ARRAY_LOT) Length: 5678 Remote Num: 1 Number of Obsevations: 1Type: 1 Track ID: 12345 Time Tag: 58573.00000000 Band ID: 1 AD ID: 21 Scan ID: 0 LRT/HRT: 1 Valid Flag: 0MSN_RAM (0:32) Observation #30 Rx'd at: (58569.000) Msg. Time: (58569.000) Forward to IMU: true Rcv Date: 2010121 Synch: f0f0 Rep Mode: Replay_Mode Fmt: 10 (AIRBORN__ARRAY_LOT) Length: 5678 Remote Num: 1 Number of Obsevations: 2Type: 1 Track ID: 12345 Time Tag: 58583.00000000 Band ID: 1 AD ID: 31 Scan ID: 0 LRT/HRT: 1 Valid Flag: 0Type: 1 Track ID: 12345 Time Tag: 58585.00000000 Band ID: 1 AD ID: 32 Scan ID: 0 LRT/HRT: 1 Valid Flag: 0
Note: There is no 2nd MSN_BER data block.
I’m using the following search pattern and REGEXP function to extract the time tag and AD ID values:
exp = '([\d\.]+)\s+Band[^A]+?AD ID:\s+(\d+).';tokens3 = regexp(bufferSplit{BlockId}, exp, 'tokens');
This results in: tokens3 = {1×2 cell} {1×2 cell} {1×2 cell},
where the time tag and AD ID are contained in the cells for each occurrence in the block of text.
>> tokens3{1,1}
ans = '58573.00000000' '21'
>> tokens3{1,2}
ans = '58583.00000000' '31'
>> tokens3{1,3}
ans = '58585.00000000' '32'
What I’m attempting to accomplish is limit the search pattern. Specifically, limit the number of times to search for the time tag and AD ID values based on the fact that there is no 2nd MSN_BER data block. I know the command option 'once' will return only the first match found. However, there could be multiple occurrences of the AD ID and its associated time tag.
The result of this would be: tokens3 = {1×2 cell}
>> tokens3{1,1}
ans = '58573.00000000' '21'
Can this be accomplished using the REGEXP function?
Best Answer