सबएक्सप्रेशन/मेटाकैरेक्टर “\t” टैब स्पेस से मिलान करता है।
उदाहरण 1
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
उदाहरण 2
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