How to filter certain parts of a string.
    7 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Nom
 il 17 Set 2019
  
    
    
    
    
    Commentato: Walter Roberson
      
      
 il 24 Giu 2022
            Hello,
So I have a string file which has a ton of data in it.
Let's say it looks like this:
"Introduction:
x1x1x1x1x1x1x1x1x1x1x1x1x1
Summary:
x2x2x2x2x2x2x2x2x22x2x2x2
Conclusion:"
What I would want to do is setup a filter so that it reads the keyword Introduction and Summary and captures everything in between. While ignoring everything else.
In this case it should be
 "Introduction: 
x1x1x1x1x1x1x1x1x1x1x1x1x1"
If it helps, I am running a script with this code to generate this string file after reading the contents from a word document:
word = actxserver('Word.Application');
word.visible = 0;
wdoc = word.Documents.Open('wordfile.docx');
x = splitlines(string(wdoc.Content.Text));  
wdoc.Close;
word.Quit; 
0 Commenti
Risposta accettata
  Walter Roberson
      
      
 il 17 Set 2019
        
      Modificato: Walter Roberson
      
      
 il 17 Set 2019
  
      S = char(wdoc.Content.Text);
x = regexp(S, '^Introduction:.*?(?=^\nSummary:)', 'match', 'lineanchors');
10 Commenti
  greenyellow22
 il 23 Giu 2022
				Hey Walter! I thought I might just ask you directly. I have a table of which one of the columns includes text. Some cells of this column look like this: 'New Scene was loaded: Castle' or 'New Scene was loaded: World1'.
I want to filter out/split for all cells with the text 'New Scene was loaded:' the last word e.g. 'Castle' or 'World1' and insert it into a new column. Can you tell me how I can split these cells based on this rule? I appreciate any help!! :)
  Walter Roberson
      
      
 il 24 Giu 2022
				TableName.NewColumnName = regexp(TableName.ColumnName, '(?<=New Scene was loaded:\s+)\S+', 'match', 'once')
There is a possibility that TableName.ColumnName might need to be {TableName.ColumnName} but I think it unlikely.
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Characters and Strings in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


