স্ট্রিং সেট করা:
string str = "Cookie and Session";
শেষ ২ ক্যারেক্টার বের করার জন্য Regex:
Regex.Match(str, @"(.{2})\s*$")
সম্পূর্ণ কোড
using System;
using System.Text.RegularExpressions;
public class Demo {
public static void Main() {
string str = "Cookie and Session";
Console.WriteLine(Regex.Match(str, @"(.{2})\s*$"));
}
}
আউটপুট
on
Regex ব্যাখ্যা: (.{2}) - শেষ থেকে ২টি যেকোনো ক্যাপচার করে, \s*$ - ঐচ্ছিক হোয়াইটস্পেস সহ স্ট্রিংয়ের শেষে মিল করে।
নোট: এটি C# কোড, C++ নয়। C++-এ std::regex ব্যবহার করে একই কাজ করা যায়।