title: How to split text in more than one column simultaneously
body: <p>I have a dataframe in which I keep a whole load of information about the text I am interested in (parts of speech mainly). The data is kept in the same format as the original text it is extracted for (each part of speech is semi-colon separated and each sentence is separated by a newline.</p>
  
  <p>I want to query the parts of speech sometimes for different things, like getting a sentence that has <code>NOUN PUNCT NOUN NOUN NOUN</code> in sequence and then all lines that have this to the dataframe and a further column that tells me the text that this relates to. I want to get the same data for the <code>head_token_id</code>.</p>
  
  <p>I guess I have to convert the newlines into a list, get the index of any line that shows me a match for a regular expression search and then retrieve the same index in neighbouring columns but I dont know how to do this. My data structure is below with some fake data:</p>
  
  <p><strong>Data</strong></p>
  
  <pre><code>  structure(list(sentence = c(",\n,Biopsies taken from top of stricture-metal marking clips in situ.\n,Diaphragmatic pinch:40cm .,She has a small hiatus hernia .\nDr. Martin, Marche Date of procedure: 2009-11-11 Endoscopist:\nDr. Sullivan, Shelby Second endoscopist: Dr. al-Basha, Mahfoodha Medications:\nExtent of Exam: GOJ Indications: Follow-up ULCER HEALING Procedure Performed: Gastroscopy (OGD) Findings:\nFentanyl 12.5mcg Midazolam 6mg Instrument: FG5\nHALO 90 done with good effect Endoscopic Diagnosis:\nHe is on Barrett's Screeling List in October 2017 at St Thomas'.\nHospital: Random NHS Foundation Trust Hospital Number: J6044658\nNo evidence of Barrett's oesophagus, short 2 cn hiatus hernia.\n,Oesophageal biopsies taken from three levels as requested.\n,OGD today to assess for ulceration/ongoing bleeding.\nPatient Name: Jargon, Victoria General Practitioner:\nPost chemo-radiotherapy stricture\n,The varices flattened well with air insufflation.\nTiny erosions at the antrum.\nWe will re-book for 2 weeks, rebanding.", 
  "Date of procedure: 2008-06-15 Endoscopist:\nDr. al-Safi, Lutfiyya\nDr. Kekich, Annabelle Second endoscopist: Dr. Needham, April Medications:\nDuodenitis with a small erosion .\nEndoscopic Diagnosis:\nEsophageal candidiasis\nExtent of Exam: Pylorus Indications: Weight Loss Procedure Performed: Gastroscopy (OGD) Findings: Duodenum:\nFentanyl 125mcg Midazolam 7mg Instrument: FG6\nHospital: Random NHS Foundation Trust Hospital Number: Y6417773 Patient Name: Powell, Destiny General Practitioner:\n,STOMACH: diffuse gastritis with angiodysplasia and punctate bleeding site on greater curve mid body - no obvious ulcer- antrum scar ?,No immediate complications.\n,Z-line at: 38cm - Bravo placed at 32cm- good positionat check endoscopy."
  ), HospitalNumber = c(" J6044658\n", " Y6417773\n"), upos = c("PUNCT;PUNCT;PUNCT\nPUNCT;AUX;VERB;ADP;NOUN;ADP;NOUN;PUNCT;NOUN;NOUN;NOUN;ADP;NOUN;PUNCT\nPUNCT;ADJ;NOUN;NUM;NOUN;PUNCT;PUNCT;PRON;VERB;DET;ADJ;NOUN;NOUN;PUNCT\nPROPN;PROPN;PUNCT;DET;NOUN;ADP;NOUN;PUNCT;NUM;SYM;NUM;SYM;NUM;NOUN;PUNCT\nPROPN;PROPN;PUNCT;PROPN;PROPN;NOUN;PUNCT;PROPN;PROPN;PUNCT;PROPN;PUNCT;PROPN;NOUN;PUNCT\nNOUN;ADP;PROPN;PUNCT;PROPN;NOUN;PUNCT;NOUN;PUNCT;NOUN;ADP;PROPN;PROPN;PROPN;PUNCT;PROPN;PUNCT;PROPN;PUNCT;NOUN;PUNCT\nVERB;NUM;NOUN;PROPN;NUM;NOUN;NOUN;PUNCT;NUM\nSYM;NUM;ADJ;ADP;ADJ;NOUN;PROPN;PROPN;PUNCT\nPRON;AUX;ADP;PROPN;PART;NOUN;NOUN;ADP;PROPN;NUM;ADP;PROPN;PROPN;PUNCT;PUNCT\nNOUN;PUNCT;PROPN;PROPN;PROPN;PROPN;PROPN;PROPN;PUNCT;PROPN\nDET;NOUN;ADP;PROPN;PART;NOUN;PUNCT;ADJ;NUM;NOUN;NOUN;NOUN;PUNCT\nPUNCT;ADJ;NOUN;VERB;ADP;NUM;NOUN;SCONJ;VERB;PUNCT\nVERB;NOUN;PART;VERB;ADP;NOUN;PUNCT;ADJ;NOUN;PUNCT\nADJ;NOUN;PUNCT;PROPN;PUNC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;6;13;13;20;13;14;14;18;14;18;6;1\n0;3;7;3;6;7;1;1;1\n3;1;0;8;6;8;8;3;3\n7;7;7;7;4;7;0;9;7;9;13;13;7;13;7\n0;1;6;3;3;7;1;7;7;7\n2;0;6;6;4;2;2;11;10;11;12;2;2\n3;3;0;3;7;7;4;9;4;3\n0;1;4;1;6;4;9;9;6;1\n2;0;2;8;4;4;4;2;2\n0;4;4;5;1\n4;3;4;0;4;8;8;4;4\n2;0;5;5;2;2\n3;3;0;5;3;8;8;5;3;3;3", 
  "0;3;1;1;1;7;5;9;7;1;10\n0;1;1;1;1;1\n0;1;1;1;1;1;1;1;8;1;12;1;1\n0;5;5;5;1;1\n0;1;1\n2;0\n0;3;1;1;6;1;6;10;10;6;17;13;11;15;13;13;1;17;17;17\n2;0;6;3;6;2;2;2\n0;1;6;3;3;7;1;1;12;12;12;8;12;12;18;18;16;14;1\n2;0;2;2;4;7;5;9;4;9;10;16;14;16;16;10;2;23;23;22;22;23;2;2;2;28;28;2;2\n3;3;9;7;7;7;3;7;10;0;18;13;15;15;16;18;18;10;10"
  )), row.names = c(NA, -2L), class = "data.frame")
  </code></pre>
  
  <p>Desired output if I am looking for <code>NOUN PUNCT NOUN NOUN NOUN</code> (joined with the original dataframe)</p>
  
  <pre><code>Match_sentence
  1. ",Biopsies taken from top of stricture-metal marking clips in situ."
  2. "Extent of Exam: Pylorus Indications: Weight Loss Procedure Performed: Gastroscopy (OGD) Findings: Duodenum:"
  </code></pre>