Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Java

Java में रेगुलर एक्सप्रेशन \t मेटाकैरेक्टर


सबएक्सप्रेशन/मेटाकैरेक्टर “\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

  1. - Java में रेगुलर एक्सप्रेशन . (डॉट) मेटाकैरेक्टर

    सबएक्सप्रेशन/मेटाकैरेक्टर “.” न्यूलाइन को छोड़कर किसी भी सिंगल कैरेक्टर से मिलान करता है। उदाहरण1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatchesAll { public static void main( String args[] ) { String regex = .; String input

  1. - Java में रेगुलर एक्सप्रेशन $ (डॉलर) मेटाकैरेक्टर

    सबएक्सप्रेशन/मेटाकैरेक्टर “$” लाइन के अंत से मिलान करता है। उदाहरण 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class EndWith { public static void main( String args[] ) { String regex = Tutorialspoint$; String input = Hi how are you w

  1. - Java में रेगुलर एक्सप्रेशन ^ (कैरेट) मेटाकैरेक्टर

    सबएक्सप्रेशन/मेटाकैरेक्टर “^” लाइन की शुरुआत से मिलान करता है। यदि आप इसे रेगुलर एक्सप्रेशन में उपयोग करते हैं, तो यह इनपुट स्ट्रिंग में इसके बाद आने वाले वाक्य से मिलान करता है। उदाहरण 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample {