Hi all,
I have a very large text file which I imported as a char. vector which whas the following pattern:
text=NEW SCOMPONENT /JAFHB0099 DESC 'FLANGE F7805 SLIP-ON 10K FF 900A' GTYP FLAN PARA 900 1095 56 FBIA BWD 13 END NEW SCOMPONENT /JAFHB00aa DESC 'FLANGE F7805 SLIP-ON 10K FF 1100A' GTYP FLAN PARA 1100 1225 18 FBIA BWD 14 END
I want to replace the parts after DESC and PARA with some of my own values, e.g.
nDESC = {'Description 1'; 'Description 2'} ; nPARA = {'1500 15300 20 FBDIA BWD 14' ; '1600 1623 20 FBDIA SWM 13'} ;
For the above, I have developed the following code, also with the help of the MATLAB community which let me know about the regexp function:
%Extracts what lies after the word PARA in the PARA line & Replaces it with the nPARA
newtext = regexprep(text, 'PARA\s+(\d+\.?\d*\s+\d+\.?\d*\s+\d+\.?\d*\s+\w*\s+w*\s+\d+\.?\d*)', nPARA) ;
I follow a similar logic for the case of the DESC.
However 2 problems occur.
1. The parenthesis after the \s+ and \w* for some reason do not capture the tokens only in the parenthesis after the PARA word, which instead of returning 1100 1225 18 FBIA BWD 14, I get PARA 1100 1225 18 FBIA BWD 14. However I can work around this so its not a big deal, I should be missing something out there.
2. The result that I get from the above does not replace each individual line with each string in the cell array, however it takes the last cell in the cell array and replaces every line with that cell.
Best Answer