English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
[] ” within the match/Subexpression “ [] Matching with all specified characters. Therefore, to match all letters, specify the vowel letters as shown-
[aeiouAEIOU]
import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatchVowels { public static void main( String args[] ) { String regex = "[aeiouAEIOU]"; System.out.println("Geben Sie den Eingabestring ein: "); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regulären Ausdruck kompilieren Pattern.compile(regex); //Regulären Ausdruck kompilieren Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(input); if(matcher.find()) { System.out.println("Der Eingabestring enthält Vokale"); } else { System.out.println("Der Eingabestring enthält keine Vokale"); } } }
Ausgaberesultat
Geben Sie den Eingabestring ein: Hallo, wie geht es dir? Willkommen Der Eingabestring enthält Vokale
import java.util.Scanner; public class Test { public static void main( String args[] ) { String regex = "[aeiouAEIOU]"; System.out.println("Geben Sie den Eingabestring ein: "); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); boolean result = input.matches(regex); if(result) { System.out.println("Der Eingabestring enthält Vokale"); } else { System.out.println("Der Eingabestring enthält keine Vokale"); } } }
Ausgaberesultat
Geben Sie den Eingabestring ein: Hallo, wie geht es dir? Willkommen Der Eingabestring enthält keine Vokale