English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
حرف بسيط "[]" يطابق جميع الأحرف المحددة. التعبير التالي يطابق الأحرف غير xyz.
"[xyz]"
بالمثل، التعبير التالي يطابق جميع الأحرف الميتة في النص المدخل.
"([^aeiouAEIOU0-9\\W]+)";
ثم، يمكنك استخدام النص الفارغ "" لتغيير الأحرف المدخلة، باستخدام طريقة replaceAll().
public class RemovingVowels { public static void main( String args[] ) { String input = "Hi welcome to w3codebox"; String regex = "[aeiouAEIOU]"; String result = input.replaceAll(regex, ""); System.out.println("النتيجة: " + result); } }نتيجة الإخراج
النتيجة: H wlcm t ttrlspnt
استيراد java.util.Scanner; استيراد java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { public static void main( String args[] ) { Scanner sc = new Scanner(System.in); System.out.println("إدخل النص المطلوب:\ String input = sc.nextLine(); String regex = "[aeiouAEIOU]"; String constants = ""; System.out.println("الخط النصي الدخل:\n"+input); //إنشاء عنصر نمط Pattern pattern = Pattern.compile(regex); //تطابق النمط المعدل Matcher matcher = pattern.matcher(input); //إنشاء منطقية من النصوص الفارغة StringBuffer sb = new StringBuffer(); while (matcher.find()) { constants = constants+matcher.group(); matcher.appendReplacement(sb, ""); } matcher.appendTail(sb); System.out.println("نتيجة:\n"+ sb.toString()+constants ); } }نتيجة الإخراج
إدخل النص المطلوب: هذا نص امتحاني الخط النصي الدخل: هذا نص امتحاني نتيجة: ths s smpl txtiiaaee