7 ký tự non-printable phổ biến
| Tên | Ký tự escape | Hex |
| Bell | \a | 0x07 |
| Escape | \e | 0x1B |
| Form feed | \f | 0x0C |
| Line feed | \n | 0x0A |
| Carriage return | \r | 0x0D |
| Horizontal tab | \t | 0x09 |
| Vertical tab | \v | 0x0B |
Ví dụ 1: Đếm tab bằng \t
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Nhập văn bản: ");
String input = sc.nextLine();
String regex = "\\t";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);
int count = 0;
while (matcher.find()) {
count++;
}
System.out.println("Số tab: " + count);
}
}
sample text with tab spaces
Số tab: 3
Ví dụ 2: Dùng hex \x09
String regex = "\\x09"; // hex của tab
// Kết quả tương tự
Nhập văn bản: sample data with tab spaces
Số tab: 4
Các escape sequence khác
\\n - newline (LF)
\\r - carriage return (CR)
\\r\\n - Windows line ending
\\x{1F} - Unicode control char (Java 9+)
Ứng dụng
- Làm sạch dữ liệu: xóa control char rác
- Parse file binary/text mixed
- Validate input không chứa ký tự điều khiển