সাবএক্সপ্রেশন/মেটাক্যারেক্টার "\t" ট্যাব স্পেস ম্যাচ করে।
উদাহরণ ১: ট্যাব স্পেস গণনা
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample {
public static void main(String args[]) {
String regex = "\\t";
Scanner sc = new Scanner(System.in);
System.out.println("একটি স্ট্রিং দিন: ");
String input = sc.nextLine();
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
int count = 0;
while (m.find()) {
count++;
}
System.out.println("ট্যাব স্পেস সংখ্যা: " + count);
}
}
আউটপুট
একটি স্ট্রিং দিন: This is a sentence with tab spaces ট্যাব স্পেস সংখ্যা: 6
উদাহরণ ২: ট্যাবকে স্পেস দিয়ে রিপ্লেস
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample {
public static void main(String args[]) {
String regex = "\\t";
Scanner sc = new Scanner(System.in);
System.out.println("একটি স্ট্রিং দিন: ");
String input = sc.nextLine();
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
int count = 0;
String result = "";
while (m.find()) {
result = m.replaceAll(" ");
}
System.out.println("ফলাফল: " + result);
}
}
আউটপুট
একটি স্ট্রিং দিন: This is a sentence with tab spaces ফলাফল: This is a sentence with tab spaces
নোট: উদাহরণ ২-এ ইনপুটে ট্যাব থাকলে সেগুলো স্পেস দিয়ে রিপ্লেস হয়ে যাবে। জাভা স্ট্রিং লিটারেলে \\t লিখতে হয় (এসকেপ সিকোয়েন্স)।