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

Le caractère d'expression régulière "\ Z" en Java

Expression sous-traitée/Le caractère de métacaractère "\ Z" correspond à la fin entière de la chaîne, mais à l'exception des caractères de fin de ligne autorisés.

Exemple1

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample {}}
   public static void main( String args[] ) {
      String regex = "w3codebox\\z";
      String input = "Hi how are you welcome to w3codebox";
      Pattern p = Pattern.compile(regex);
      Matcher m = p.matcher(input);
      int count = 0;
      while(m.find()) {
         count++;
      }
      System.out.println("Nombre de correspondances: ");+count);
   }
}

Résultat de la sortie

Nombre de correspondances: 1

Exemple2

Le programme Java suivant vérifie si le texte d'entrée donné se termine par un chiffre.

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Data {
   public static void main( String args[] ) {
      String regex = "[0-9]\\z";
      String input = "Hi how are you \n this is sample text \n this is third line 554";
      Pattern p = Pattern.compile(regex);
      Matcher m = p.matcher(input);
      if(m.find()) {
         System.out.println("Donnée d'entrée se termine par un chiffre");
      } else {
         System.out.println("Donnée d'entrée ne se termine pas par un chiffre");
      }
   }
}

Résultat de la sortie

Donnée d'entrée se termine par un chiffre
Vous pourriez aussi aimer