MSL by example:Regular Expressions

From MSL-Libraries
Revision as of 16:02, 16 February 2010 by Senes (talk | contribs) (Created page with '== Regular Expressions == // Generic string matching string regExpression = "^CLUSTAL W (\\S+)\\s+([\\S\\s]+)$"; string lineToMatch="CLUSTAL W 2.1 multiple sequence alignment…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Regular Expressions

// Generic string matching
string regExpression = "^CLUSTAL W (\\S+)\\s+([\\S\\s]+)$";
string lineToMatch="CLUSTAL W 2.1 multiple sequence alignment";

vector<string> results;

// Line which should match RegEx
if (MslTools::regex(lineToMatch,regExpression,results)){

  cout << "PASS test 1\n"; 

  // Print out the matched '()' substrings
  for (uint i = 0; i < results.size();i++){
    cout << "Match["<<i<<"]: "<<results[i]<<endl;
  }

} else {
  cerr << "ERROR did not match line properly.\n";
}