सामान्यतः उपयोग किए जाने वाले 7 नॉन-प्रिंटेबल वर्ण हैं और प्रत्येक वर्ण का अपना हेक्साडेसिमल प्रतिनिधित्व होता है।
| नाम | वर्ण | हेक्साडेसिमल प्रतिनिधित्व |
|---|---|---|
| बेल (Bell) | \a | 0x07 |
| एस्केप (Escape) | \e | 0x1B |
| फॉर्म फीड (Form feed) | \f | 0x0C |
| लाइन फीड (Line feed) | \n | 0x0A |
| कैरिज रिटर्न (Carriage return) | \r | 0X0D |
| हॉरिजॉन्टल टैब (Horizontal tab) | \t | 0X09 |
| वर्टिकल टैब (Vertical tab) | \v | 0X0B |
उदाहरण 1
निम्नलिखित Java प्रोग्राम एक इनपुट टेक्स्ट स्वीकार करता है और इसमें टैब स्पेस की संख्या गिनता है:
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter input text: ");
String input = sc.nextLine();
String regex = "\\t";
// पैटर्न ऑब्जेक्ट बनाना
Pattern pattern = Pattern.compile(regex);
// स्ट्रिंग में संकलित पैटर्न का मिलान
Matcher matcher = pattern.matcher(input);
int count = 0;
while (matcher.find()) {
count++;
}
System.out.println("Number of tab spaces in the given input text: " + count);
}
}
आउटपुट
sample text with tab spaces Number of tab spaces in the given input text: 3
उदाहरण 2
आप नॉन-प्रिंटेबल वर्णों के संबंधित हेक्साडेसिमल प्रतिनिधित्व का उपयोग करके भी मिलान कर सकते हैं।
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter input text: ");
String input = sc.nextLine();
String regex = "\\x09";
// पैटर्न ऑब्जेक्ट बनाना
Pattern pattern = Pattern.compile(regex);
// स्ट्रिंग में संकलित पैटर्न का मिलान
Matcher matcher = pattern.matcher(input);
int count = 0;
while (matcher.find()) {
count++;
}
System.out.println("Number of tab spaces in the given input text: " + count);
}
}
आउटपुट
Enter input text: sample data with tab spaces Number of tab spaces in the given input text: 4