English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

مفتاح البديل \ t في تعبيرات النصوص Java

子表达式/元字符“ \ 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);
   }
}

نتيجة الإخراج

أدخل سلسلة نصية:
هذا هو جملة تحتوي على مسافات تبويب
عدد مسافات التبويب: 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);
   }
}

نتيجة الإخراج

أدخل سلسلة نصية:
هذا جملة تحتوي على مسافات تبويب
نتيجة: هذا جملة تحتوي على مسافات تبويب
أنت قد تحب