इस लेख में हम C++ STL में match_results::prefix() और match_results::suffix() फंक्शन्स के कार्य, सिंटैक्स और उदाहरणों पर चर्चा करेंगे।
C++ STL में match_results क्या है?
std::match_results एक स्पेशलाइज्ड कंटेनर-जैसी क्लास है जिसका उपयोग कैरेक्टर सीक्वेंसेस के कलेक्शन को रखने के लिए किया जाता है जो मैच होते हैं। इस कंटेनर क्लास में एक रेगेक्स मैच ऑपरेशन टारगेट सीक्वेंस के मैच ढूंढता है।
match_results::prefix() क्या है?
match_results::prefix() फंक्शन C++ STL में एक इनबिल्ट फंक्शन है, जो <regex> हेडर फाइल में परिभाषित है। prefix() का उपयोग इससे जुड़े ऑब्जेक्ट के पूर्ववर्ती match_results को प्राप्त करने के लिए किया जाता है। यह फंक्शन match_results ऑब्जेक्ट के सफल सीक्वेंस का रेफरेंस लौटाता है।
सिंटैक्स
match_results.prefix();
पैरामीटर्स
यह फंक्शन कोई पैरामीटर स्वीकार नहीं करता।
रिटर्न वैल्यू
यह फंक्शन मैच सीक्वेंस से पहले के स्ट्रिंग या सीक्वेंस का कॉन्स्टेंट रेफरेंस लौटाता है।
उदाहरण
Input: string str = "Tutorials Points"; regex R("Points"); smatch Mat; regex_search(str, Mat, R); Mat.prefix(); Output: Tutorials
उदाहरण 1
#include <bits/stdc++.h>
using namespace std;
int main() {
string str = "Tutorials Points";
regex R("Points");
smatch Mat;
regex_search(str, Mat, R);
cout << "String prefix is : ";
if (!Mat.empty()) {
cout << Mat.prefix();
}
return 0;
}
आउटपुट
String prefix is : Tutorials
match_results::suffix() क्या है?
match_results::suffix() फंक्शन C++ STL में एक इनबिल्ट फंक्शन है, जो <regex> हेडर फाइल में परिभाषित है। suffix() का उपयोग इससे जुड़े ऑब्जेक्ट के उत्तरवर्ती match_results को प्राप्त करने के लिए किया जाता है। यह फंक्शन match_results ऑब्जेक्ट के उत्तरवर्ती सीक्वेंस का रेफरेंस लौटाता है।
सिंटैक्स
match_results.suffix();
पैरामीटर्स
यह फंक्शन कोई पैरामीटर स्वीकार नहीं करता।
रिटर्न वैल्यू
यह फंक्शन मैच सीक्वेंस के बाद के स्ट्रिंग या सीक्वेंस का कॉन्स्टेंट रेफरेंस लौटाता है।
उदाहरण
Input: std::string str("Tutorials Points is the best"); std::smatch Mat; std::regex re("Points"); std::regex_match(str, Mat, re); Mat.suffix(); Output: is the best
उदाहरण 2
#include <bits/stdc++.h>
using namespace std;
int main() {
string str = "Tutorials Points is the best";
regex R("Points");
smatch Mat;
regex_search(str, Mat, R);
cout << "String prefix is : ";
if (!Mat.empty()) {
cout << Mat.suffix();
}
return 0;
}
आउटपुट
String prefix is : is the best