Difference between revisions of "MSL by example:Regular Expressions"
From MSL-Libraries
Jump to navigationJump to search (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…') |
|||
Line 1: | Line 1: | ||
== Regular Expressions == | == Regular Expressions == | ||
− | + | <source lang="cpp"> | |
− | + | // 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"; | cout << "PASS test 1\n"; | ||
Line 17: | Line 18: | ||
} | } | ||
− | + | } else { | |
cerr << "ERROR did not match line properly.\n"; | cerr << "ERROR did not match line properly.\n"; | ||
− | + | } | |
+ | </source> |
Latest revision as of 16:39, 16 February 2010
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";
}