ตัวอย่าง: ใช้ Pattern และ Matcher import java.util.regex.*; public class Demo { public static void main(String[] args) { String input = This is a sample only !$@; // Pattern: ไม่ใช่ a-z, 0-9, space (case insensitive) Pattern pattern = Pattern.compile([^a-z0-9 ]