Hướng dẫn explain any five character class with example in python - giải thích bất kỳ lớp năm ký tự nào với ví dụ trong python

Lớp nhân vật

Một "lớp ký tự", hoặc một "bộ ký tự", là một tập hợp các ký tự được đặt trong dấu ngoặc vuông. Động cơ Regex chỉ khớp với một trong số một số ký tự trong lớp ký tự hoặc bộ ký tự. Chúng tôi đặt các nhân vật chúng tôi muốn phù hợp giữa dấu ngoặc vuông. Nếu bạn muốn khớp với bất kỳ nguyên âm nào, chúng tôi sử dụng bộ ký tự [aeiou].

Một lớp ký tự hoặc tập hợp chỉ khớp với một ký tự duy nhất. Thứ tự của các ký tự bên trong một lớp hoặc bộ ký tự không quan trọng. Kết quả là giống hệt nhau.

Chúng tôi sử dụng dấu gạch nối bên trong một lớp ký tự để chỉ định một loạt các ký tự. .

Thí dụ

Mã sau tìm thấy và in tất cả các nguyên âm trong chuỗi đã cho

import re
s = 'mother of all battles'
result = re.findall[r'[aeiou]', s]
print result

Đầu ra

Điều này cung cấp cho đầu ra

['o', 'e', 'o', 'a', 'a', 'e']

Cập nhật vào ngày 18 tháng 2 năm 2020 10:49:31

  • Câu hỏi và câu trả lời liên quan
  • Các lớp ký tự lặp lại được sử dụng trong biểu thức thông thường của Python là gì?
  • Metacharacters bên trong các lớp ký tự được sử dụng trong biểu thức thông thường Python là gì?
  • Các lớp ký tự phủ định được sử dụng trong các biểu thức thông thường của Python là gì?
  • Giải thích các lớp nhân vật trong biểu thức chính quy Java
  • Làm thế nào để thoát khỏi bất kỳ nhân vật đặc biệt nào trong biểu hiện thông thường của Python?
  • Làm thế nào để phù hợp với một ký tự không phải là không gian trong Python bằng cách sử dụng biểu thức chính quy?
  • Làm thế nào để phù hợp với một ký tự duy nhất trong Python bằng cách sử dụng biểu thức chính quy?
  • Tìm ký tự không chữ số với biểu thức chính quy JavaScript.
  • Với biểu thức chính quy JavaScript, hãy tìm một ký tự không phải là màu sắc.
  • Làm thế nào để phù hợp với bất kỳ một ký tự chữ hoa nào trong Python bằng cách sử dụng biểu thức thông thường?
  • Làm thế nào để phù hợp với bất kỳ ký tự không chữ số nào trong Python bằng cách sử dụng biểu thức chính quy?
  • Các lớp nhân vật Posix Java Regex
  • Hoạt động của lớp nhân vật trong Python là gì?
  • Các trường hợp lặp lại biểu thức thường xuyên trong Python là gì?
  • Biểu thức thông thường Python nào có thể được sử dụng thay cho String.replace?

Trong bài viết này, chúng ta sẽ thấy cách sử dụng các chuỗi đặc biệt và các lớp ký tự trong Python. Trình tự đặc biệt Python Regex đại diện cho một số ký tự đặc biệt để tăng cường khả năng của biểu thức chính quy.

Trình tự đặc biệt

Trình tự đặc biệt đại diện cho các lớp ký tự được xác định trước cơ bản, có ý nghĩa duy nhất. Mỗi chuỗi đặc biệt làm cho các mẫu phổ biến cụ thể thoải mái hơn để sử dụng.special sequence represents the basic predefined character classes, which have a unique meaning. Each special sequence makes specific common patterns more comfortable to use.

Ví dụ: bạn có thể sử dụng trình tự

['o', 'e', 'o', 'a', 'a', 'e']
2 như một định nghĩa đơn giản hóa cho lớp ký tự
['o', 'e', 'o', 'a', 'a', 'e']
3, có nghĩa là khớp với bất kỳ chữ số nào từ 0 đến 9.

Hãy cùng xem danh sách các chuỗi đặc biệt của Regex và ý nghĩa của chúng. Các chuỗi đặc biệt bao gồm & nbsp; ________ 14 & nbsp; [phản ứng dữ dội] và một ký tự từ bảng dưới đây.

Trình tự đặc biệtNghĩa
['o', 'e', 'o', 'a', 'a', 'e']
5
Chỉ khớp với mẫu khi bắt đầu chuỗi
['o', 'e', 'o', 'a', 'a', 'e']
6
Chỉ khớp với mẫu ở cuối chuỗi
['o', 'e', 'o', 'a', 'a', 'e']
2
Phù hợp với bất kỳ chữ số nào. Viết tắt cho các lớp ký tự & nbsp; ________ 13
Short for character classes 
['o', 'e', 'o', 'a', 'a', 'e']
3
['o', 'e', 'o', 'a', 'a', 'e']
9
Phù hợp với bất kỳ chữ số nào.short cho & nbsp; ________ 20
short for 
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
0
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
1
Khớp với bất kỳ ký tự khoảng trắng nào.short cho lớp ký tự
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
2
short for character class
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
2
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
3
Khớp với bất kỳ ký tự không phải màu nào.short cho
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
4
short for
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
4
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
5
Khớp với bất kỳ ký tự chữ và số nào. SHORT cho lớp ký tự
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
6
short for character class
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
6
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
7
Phù hợp với bất kỳ ký tự không phải là tổng số.Short cho
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
8
short for
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
8
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
9
Khớp với chuỗi trống, nhưng chỉ ở đầu hoặc cuối của một từ. Khớp với một ranh giới từ trong đó một ký tự từ là ____ 30. Ví dụ, ‘
import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
1 khớp với‘ Jessa, ‘Jessa.
For example, ‘
import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
1 matches ‘Jessa’, ‘Jessa.’, ‘[Jessa]’, ‘Jessa Emma Kelly’ but not ‘JessaKelly’ or ‘Jessa5’.
import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
2
Đối diện với
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
9. Khớp với chuỗi trống, nhưng chỉ khi nó không ở đầu hoặc cuối của một từ
Python Regex Chuỗi đặc biệt

Trong Python, các lớp nhân vật Regex là các bộ ký tự hoặc phạm vi các ký tự được đặt bởi dấu ngoặc vuông

import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
4.character classes are sets of characters or ranges of characters enclosed by square brackets
import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
4
.

Ví dụ:

import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
5 Nó có nghĩa là khớp bất kỳ chữ cái viết thường nào từ a đến z. & Nbsp;

Hãy cùng xem một số lớp ký tự phổ biến nhất được sử dụng bên trong các mẫu biểu thức chính quy.

Lớp nhân vậtSự mô tả
import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
6
Khớp với chữ A hoặc b hoặc c
import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
7
Khớp chữ cái a hoặc b hoặc c theo sau là p hoặc q.
import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
8
Khớp với bất kỳ chữ cái nào ngoại trừ a, b hoặc c [phủ định]
['o', 'e', 'o', 'a', 'a', 'e']
3
Khớp với bất kỳ chữ số nào từ 0 đến 9. Bao gồm [phạm vi]
import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
5
Kết hợp bất kỳ chữ cái chữ thường từ a đến z. Bao gồm [phạm vi]
import re

target_str = "Jessa and Kelly!!"

# \w to match all alphanumeric characters
result = re.findall[r"\w", target_str]
print[result]
# Output ['J', 'e', 's', 's', 'a', 'a', 'n', 'd', 'K', 'e', 'l', 'l', 'y']

# \w{5} to 5-letter word
result = re.findall[r"\w{5}", target_str]
print[result]
# Output ['Jessa', 'Kelly']

# \W to match NON-alphanumeric
result = re.findall[r"\W", target_str]
print[result]
# Output [' ', ' ', '!', '!']
1
Khớp với bất kỳ chữ hoa nào từ A đến Z. bao gồm [phạm vi]
import re

target_str = "Jessa and Kelly!!"

# \w to match all alphanumeric characters
result = re.findall[r"\w", target_str]
print[result]
# Output ['J', 'e', 's', 's', 'a', 'a', 'n', 'd', 'K', 'e', 'l', 'l', 'y']

# \w{5} to 5-letter word
result = re.findall[r"\w{5}", target_str]
print[result]
# Output ['Jessa', 'Kelly']

# \W to match NON-alphanumeric
result = re.findall[r"\W", target_str]
print[result]
# Output [' ', ' ', '!', '!']
2
Khớp với bất kỳ chữ cái chữ thường hoặc chữ hoa. Bao gồm [phạm vi]
import re

target_str = "Jessa and Kelly!!"

# \w to match all alphanumeric characters
result = re.findall[r"\w", target_str]
print[result]
# Output ['J', 'e', 's', 's', 'a', 'a', 'n', 'd', 'K', 'e', 'l', 'l', 'y']

# \w{5} to 5-letter word
result = re.findall[r"\w{5}", target_str]
print[result]
# Output ['Jessa', 'Kelly']

# \W to match NON-alphanumeric
result = re.findall[r"\W", target_str]
print[result]
# Output [' ', ' ', '!', '!']
3
Phạm vi: khớp một chữ cái giữa m và p và các chữ số từ 2 đến 8, nhưng không phải P2
import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
0
Khớp với bất kỳ ký tự chữ và số nào
Các lớp nhân vật Python Regex

Bây giờ, hãy để chúng tôi xem cách sử dụng từng lớp trình tự và ký tự đặc biệt trong biểu thức thông thường của Python.

Trình tự đặc biệt
['o', 'e', 'o', 'a', 'a', 'e']
5 và
['o', 'e', 'o', 'a', 'a', 'e']
6

Backslash A [

['o', 'e', 'o', 'a', 'a', 'e']
5]

Các chuỗi

['o', 'e', 'o', 'a', 'a', 'e']
5 chỉ khớp với đầu chuỗi. Nó hoạt động giống như metacharacter caret [
import re

target_str = "Jessa and Kelly!!"

# \w to match all alphanumeric characters
result = re.findall[r"\w", target_str]
print[result]
# Output ['J', 'e', 's', 's', 'a', 'a', 'n', 'd', 'K', 'e', 'l', 'l', 'y']

# \w{5} to 5-letter word
result = re.findall[r"\w{5}", target_str]
print[result]
# Output ['Jessa', 'Kelly']

# \W to match NON-alphanumeric
result = re.findall[r"\W", target_str]
print[result]
# Output [' ', ' ', '!', '!']
9].

Mặt khác, nếu chúng ta có một chuỗi nhiều dòng, thì

['o', 'e', 'o', 'a', 'a', 'e']
5 vẫn chỉ khớp với đầu chuỗi, trong khi CARET sẽ khớp ở đầu mỗi dòng mới của chuỗi.

Trình tự Backslash Z [

['o', 'e', 'o', 'a', 'a', 'e']
6] chỉ khớp với phần cuối của chuỗi. Nó hoạt động giống như metacharacter đô la [$].sequences only match the end of the string. It works the same as the dollar [$] metacharacter.

Thí dụ

import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']

Trình tự đặc biệt ________ 12 & nbsp; và
['o', 'e', 'o', 'a', 'a', 'e']
9

Backslash D [

['o', 'e', 'o', 'a', 'a', 'e']
2]

  • ['o', 'e', 'o', 'a', 'a', 'e']
    2 khớp với bất kỳ chữ số nào từ 0 đến 9 bên trong chuỗi đích.
  • Trình tự đặc biệt này tương đương với lớp ký tự
    ['o', 'e', 'o', 'a', 'a', 'e']
    3.
    ['o', 'e', 'o', 'a', 'a', 'e']
    3
    .
  • Sử dụng
    ['o', 'e', 'o', 'a', 'a', 'e']
    2 hoặc
    ['o', 'e', 'o', 'a', 'a', 'e']
    3.

Backslash Capital D [

['o', 'e', 'o', 'a', 'a', 'e']
9]

  • Trình tự này trái ngược hoàn toàn với
    ['o', 'e', 'o', 'a', 'a', 'e']
    2 và nó phù hợp với bất kỳ ký tự không chữ số nào.
  • Bất kỳ ký tự nào trong chuỗi đích không phải là một chữ số sẽ tương đương với
    ['o', 'e', 'o', 'a', 'a', 'e']
    9.
  • Ngoài ra, bạn có thể viết
    ['o', 'e', 'o', 'a', 'a', 'e']
    9 bằng cách sử dụng lớp ký tự ____ 20 & nbsp; [Caret ^ khi bắt đầu lớp nhân vật biểu thị sự phủ định].

Thí dụ

Trình tự đặc biệt ________ 12 & nbsp; và

['o', 'e', 'o', 'a', 'a', 'e']
9

  1. Backslash D [
    ['o', 'e', 'o', 'a', 'a', 'e']
    2]
  2. ['o', 'e', 'o', 'a', 'a', 'e']
    2 khớp với bất kỳ chữ số nào từ 0 đến 9 bên trong chuỗi đích.
import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']

Trình tự đặc biệt này tương đương với lớp ký tự
['o', 'e', 'o', 'a', 'a', 'e']
3.

Sử dụng

['o', 'e', 'o', 'a', 'a', 'e']
2 hoặc
['o', 'e', 'o', 'a', 'a', 'e']
3.

  • Backslash Capital D [
    ['o', 'e', 'o', 'a', 'a', 'e']
    9]
  • Trình tự này trái ngược hoàn toàn với
    ['o', 'e', 'o', 'a', 'a', 'e']
    2 và nó phù hợp với bất kỳ ký tự không chữ số nào.
  • Bất kỳ ký tự nào trong chuỗi đích không phải là một chữ số sẽ tương đương với
    ['o', 'e', 'o', 'a', 'a', 'e']
    9.
  • Ngoài ra, bạn có thể viết
    ['o', 'e', 'o', 'a', 'a', 'e']
    9 bằng cách sử dụng lớp ký tự ____ 20 & nbsp; [Caret ^ khi bắt đầu lớp nhân vật biểu thị sự phủ định].

Bây giờ hãy để Lừa làm theo sau

  • Sử dụng chuỗi đặc biệt
    ['o', 'e', 'o', 'a', 'a', 'e']
    2 bên trong mẫu regex để tìm số 4 chữ số trong chuỗi mục tiêu của chúng tôi.
  • Sử dụng chuỗi đặc biệt
    ['o', 'e', 'o', 'a', 'a', 'e']
    9 bên trong mẫu regex để tìm tất cả các ký tự không chữ số.
  • Trình tự đặc biệt ________ 25 & nbsp; và
    import re
    
    target_str = "Jessa is a Python developer, and her salary is 8000"
    
    # \A to match at the start of a string
    # match word starts with capital letter
    result = re.findall[r"\A[[A-Z].*?]\s", target_str]
    print["Matching value", result]
    # Output ['Jessa']
    
    # \Z to match at the end of a string
    # match number at the end of the string
    result = re.findall[r"\d.*?\Z", target_str]
    print["Matching value", result]
    # Output ['8000']
    7

Thí dụ

Trình tự đặc biệt ________ 12 & nbsp; và

['o', 'e', 'o', 'a', 'a', 'e']
9

  1. Backslash D [
    ['o', 'e', 'o', 'a', 'a', 'e']
    2]
  2. ['o', 'e', 'o', 'a', 'a', 'e']
    2 khớp với bất kỳ chữ số nào từ 0 đến 9 bên trong chuỗi đích.
import re

target_str = "Jessa and Kelly!!"

# \w to match all alphanumeric characters
result = re.findall[r"\w", target_str]
print[result]
# Output ['J', 'e', 's', 's', 'a', 'a', 'n', 'd', 'K', 'e', 'l', 'l', 'y']

# \w{5} to 5-letter word
result = re.findall[r"\w{5}", target_str]
print[result]
# Output ['Jessa', 'Kelly']

# \W to match NON-alphanumeric
result = re.findall[r"\W", target_str]
print[result]
# Output [' ', ' ', '!', '!']

Trình tự đặc biệt này tương đương với lớp ký tự
['o', 'e', 'o', 'a', 'a', 'e']
3.

Sử dụng

['o', 'e', 'o', 'a', 'a', 'e']
2 hoặc
['o', 'e', 'o', 'a', 'a', 'e']
3.

Backslash Capital D [

['o', 'e', 'o', 'a', 'a', 'e']
9]

  • Trình tự này trái ngược hoàn toàn với
    ['o', 'e', 'o', 'a', 'a', 'e']
    2 và nó phù hợp với bất kỳ ký tự không chữ số nào.
  • Bất kỳ ký tự nào trong chuỗi đích không phải là một chữ số sẽ tương đương với
    ['o', 'e', 'o', 'a', 'a', 'e']
    9.
  • Ngoài ra, bạn có thể viết
    ['o', 'e', 'o', 'a', 'a', 'e']
    9 bằng cách sử dụng lớp ký tự ____ 20 & nbsp; [Caret ^ khi bắt đầu lớp nhân vật biểu thị sự phủ định].
  • Bây giờ hãy để Lừa làm theo sau
  • Sử dụng chuỗi đặc biệt
    ['o', 'e', 'o', 'a', 'a', 'e']
    2 bên trong mẫu regex để tìm số 4 chữ số trong chuỗi mục tiêu của chúng tôi.
  • Sử dụng chuỗi đặc biệt
    ['o', 'e', 'o', 'a', 'a', 'e']
    9 bên trong mẫu regex để tìm tất cả các ký tự không chữ số.

Trình tự đặc biệt ________ 25 & nbsp; và

import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
7

Backslash W [

import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
5]

import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
5 phù hợp với bất kỳ ký tự chữ và số nào, còn được gọi là ký tự từ.

Điều này bao gồm các chữ cái chữ thường và chữ hoa, các chữ số 0 đến 9 và ký tự dấu gạch dưới.

Thí dụ

Bây giờ hãy để Lừa làm theo sau

  1. Sử dụng trình tự đặc biệt
    import re
    
    target_str = "Jessa is a Python developer, and her salary is 8000"
    
    # \A to match at the start of a string
    # match word starts with capital letter
    result = re.findall[r"\A[[A-Z].*?]\s", target_str]
    print["Matching value", result]
    # Output ['Jessa']
    
    # \Z to match at the end of a string
    # match number at the end of the string
    result = re.findall[r"\d.*?\Z", target_str]
    print["Matching value", result]
    # Output ['8000']
    1 bên trong mẫu regex để tìm tất cả ký tự khoảng trắng trong chuỗi đích của chúng tôi
  2. Sử dụng trình tự đặc biệt
    import re
    
    target_str = "Jessa is a Python developer, and her salary is 8000"
    
    # \A to match at the start of a string
    # match word starts with capital letter
    result = re.findall[r"\A[[A-Z].*?]\s", target_str]
    print["Matching value", result]
    # Output ['Jessa']
    
    # \Z to match at the end of a string
    # match number at the end of the string
    result = re.findall[r"\d.*?\Z", target_str]
    print["Matching value", result]
    # Output ['8000']
    3 bên trong mẫu regex để tìm tất cả các ký tự không phải là màu
import re

target_str = "Jessa \t \n  "

# \s to match any whitespace
result = re.findall[r"\s", target_str]
print[result]
# Output [' ', ' ', '\t', ' ', '\n', ' ', ' ']

# \S to match non-whitespace
result = re.findall[r"\S", target_str]
print[result]
# Output ['J', 'e', 's', 's', 'a']

# split on white-spaces
result = re.split[r"\s+", "Jessa and Kelly"]
print[result]
# Output ['Jessa', 'and', 'Kelly']

# remove all multiple white-spaces with single space
result = re.sub[r"\s+", " ", "Jessa   and   \t \t Kelly  "]
print[result]
# Output 'Jessa and Kelly '

Trình tự đặc biệt ________ 29 & NBSP; và
import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
2

Backslash chữ thường B [

import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
9]

Trình tự đặc biệt

import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
9 phù hợp với các chuỗi trống giáp với từ. & Nbsp; Backslash
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
9 được sử dụng trong các mẫu biểu thức chính quy để báo hiệu các ranh giới từ hoặc nói cách khác, các đường viền hoặc cạnh của một từ.

LƯU Ý: Một từ là một tập hợp các ký tự chữ và số được bao quanh bởi các ký tự không phải là ký tự [như không gian].

Thí dụ

Hãy cùng cố gắng khớp với tất cả các từ 6 chữ cái bằng cách sử dụng chuỗi đặc biệt

import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
5 và & nbsp;
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
9

import re

target_str = "  Jessa salary is 8000$ She is Python developer"

# \b to word boundary
# \w{6} to match six-letter word
result = re.findall[r"\b\w{6}\b", target_str]
print[result]
# Output ['salary', 'Python']

# \b need separate word not part of a word
result = re.findall[r"\bthon\b", target_str]
print[result]
# Output []

Note: 

Một điều cần thiết cần ghi nhớ ở đây là trận đấu sẽ chỉ được thực hiện cho chính từ hoàn chỉnh và riêng biệt. Không có trận đấu nào được trả lại nếu từ được chứa bên trong một từ khác.

Chẳng hạn, xem xét cùng một chuỗi mục tiêu, chúng ta có thể tìm kiếm từ SSA SSA bằng cách sử dụng chuỗi đặc biệt

import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
9 như thế này
['o', 'e', 'o', 'a', 'a', 'e']
08. Nhưng chúng tôi sẽ không có được một trận đấu vì các ký tự không phải là đồngumeric không giáp với cả hai phía.ssa” using a
import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
9 special sequence like this
['o', 'e', 'o', 'a', 'a', 'e']
08. But we will not get a match because non-alphanumeric characters do not border it on both sides.

Hơn nữa, trình tự

import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
9 luôn khớp với chuỗi trống hoặc ranh giới giữa một ký tự chữ và số và ký tự không phải là vô cầu.

Do đó, hãy nhớ rằng từ mà bạn đang cố gắng phù hợp với sự trợ giúp của chuỗi đặc biệt

import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
9 nên được tách biệt, không phải là một phần của một từ.

Backslash Capital B [

import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
2]

Trình tự này trái ngược hoàn toàn với

import re

target_str = "Jessa is a Python developer, and her salary is 8000"

# \A to match at the start of a string
# match word starts with capital letter
result = re.findall[r"\A[[A-Z].*?]\s", target_str]
print["Matching value", result]
# Output ['Jessa']

# \Z to match at the end of a string
# match number at the end of the string
result = re.findall[r"\d.*?\Z", target_str]
print["Matching value", result]
# Output ['8000']
9.

Mặt khác, trình tự đặc biệt

import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
2 khớp với chuỗi trống hoặc đường viền giữa hai ký tự chữ và số hoặc hai ký tự không phải là vô cảm khi nó không ở đầu hoặc ở cuối một từ.

Vì vậy, chuỗi này có thể hữu ích cho việc khớp và định vị một số chuỗi trong một từ cụ thể.

Ví dụ: hãy để sử dụng

import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
2 để kiểm tra xem chuỗi ‘thon có nằm trong chuỗi đích nhưng không phải ở đầu một từ hay không. Vì vậy, ‘Thon nên là một phần của một từ lớn hơn trong chuỗi của chúng tôi, nhưng không phải ở đầu từ.thon‘ is inside the target string but not at the beginning of a word. So ‘thon‘ should be part of a larger word in our string, but not at the beginning of the word.

Thí dụ

import re

target_str = "Jessa salary is 8000$ She is Python developer"

# \B
result = re.findall[r"\Bthon", target_str]
print[result]
# Output ['thon']

Và thực sự, chúng ta có một trận đấu của

['o', 'e', 'o', 'a', 'a', 'e']
15 bên trong từ "Python" không ở đầu từ này. Điều gì sẽ xảy ra nếu chúng ta muốn kiểm tra xem
['o', 'e', 'o', 'a', 'a', 'e']
15 là một phần của một từ trong chuỗi đích nhưng không phải ở cuối từ đó.

Chà, chúng ta phải di chuyển chuỗi

import re

target_str = "8000 dollar"

# \d to match all digits
result = re.findall[r"\d", target_str]
print[result]
# Output ['8', '0', '0', '0']

# \d to match all numbers
result = re.findall[r"\d+", target_str]
print[result]
# Output ['8000']

# \D to match non-digits
result = re.findall[r"\D", target_str]
print[result]
# Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
2 ở cuối mẫu. Hãy thử thử này.

result = re.findall[r"thon\B", target_str]

Tạo các lớp ký tự tùy chỉnh

Chúng ta có thể xây dựng các lớp ký tự bằng cách sử dụng các cách sau

  1. Các lớp học đơn giản
  2. Phủ định
  3. các dãy

Các lớp nhân vật đơn giản

Hình thức cơ bản nhất của một lớp ký tự là đặt một tập hợp các ký tự cạnh nhau trong khung vuông.

Ví dụ, biểu thức thông thường

['o', 'e', 'o', 'a', 'a', 'e']
18 sẽ khớp với các từ ngữ Pot Pot, hot hot, hoặc rất nhiều vì nó định nghĩa một lớp nhân vật chấp nhận 'P', 'H' hoặc 'l' là nhân vật đầu tiên của nó theo sau là ' ot '.
['o', 'e', 'o', 'a', 'a', 'e']
18
will match the words “pot”, “hot”, or “lot” because it defines a character class accepting either ‘p’, ‘h’, or ‘l’ as its first character followed by ‘ot’.

Hãy cùng xem ví dụ Python về cách sử dụng các lớp ký tự đơn giản trong mẫu biểu thức chính quy.

import re

target_string = "Jessa loves Python. and her salary is 8000$"

# simple character Class [jds]
# Match the letter J or d or e
result = re.findall[r"[Jde]", target_string]
print[result]
# Output ['J', 'e', 'e', 'd', 'e']

# simple character Class [0-9]
# Match any digit
result = re.findall[r"[0-9]", target_string]
print[result]
# Output ['8', '0', '0', '0']

# character Class [abc][pq]
# Match Match p or y or t followed by either h or s.
result = re.findall[r"[Pyt][hs]", target_string]
print[result]
# Output ['th']

Sử dụng phủ định để xây dựng các lớp ký tự

Để phù hợp với tất cả các ký tự ngoại trừ các ký tự được liệt kê trong khung vuông, hãy chèn

['o', 'e', 'o', 'a', 'a', 'e']
19 Metacharacter ở lớp nhân vật bắt đầu. Kỹ thuật này được gọi là & nbsp; phủ định.

  1. import re
    
    target_str = "8000 dollar"
    
    # \d to match all digits
    result = re.findall[r"\d", target_str]
    print[result]
    # Output ['8', '0', '0', '0']
    
    # \d to match all numbers
    result = re.findall[r"\d+", target_str]
    print[result]
    # Output ['8000']
    
    # \D to match non-digits
    result = re.findall[r"\D", target_str]
    print[result]
    # Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
    8 khớp với bất kỳ ký tự nào ngoại trừ a, b hoặc c
  2. import re
    
    target_str = "Jessa is a Python developer, and her salary is 8000"
    
    # \A to match at the start of a string
    # match word starts with capital letter
    result = re.findall[r"\A[[A-Z].*?]\s", target_str]
    print["Matching value", result]
    # Output ['Jessa']
    
    # \Z to match at the end of a string
    # match number at the end of the string
    result = re.findall[r"\d.*?\Z", target_str]
    print["Matching value", result]
    # Output ['8000']
    0 khớp với bất kỳ ký tự nào ngoại trừ các chữ số

Example::

['o', 'e', 'o', 'a', 'a', 'e']
0

Sử dụng phạm vi để xây dựng các lớp ký tự

Đôi khi, bạn sẽ muốn xác định một lớp ký tự bao gồm một loạt các giá trị, chẳng hạn như các chữ cái M M đến P Piến hoặc các số từ 2 đến 6. Để chỉ định một phạm vi, chỉ cần chèn metacharacter

['o', 'e', 'o', 'a', 'a', 'e']
22 giữa ký tự đầu tiên và ký tự cuối cùng được khớp, chẳng hạn như
['o', 'e', 'o', 'a', 'a', 'e']
23 hoặc
['o', 'e', 'o', 'a', 'a', 'e']
24.m through p” or the numbers “2 through 6“. To specify a range, simply insert the
['o', 'e', 'o', 'a', 'a', 'e']
22 metacharacter between the first and last character to be matched, such as
['o', 'e', 'o', 'a', 'a', 'e']
23 or
['o', 'e', 'o', 'a', 'a', 'e']
24.

Hãy cùng xem cách sử dụng các phạm vi để xây dựng các lớp ký tự Regex.

  • import re
    
    target_str = "8000 dollar"
    
    # \d to match all digits
    result = re.findall[r"\d", target_str]
    print[result]
    # Output ['8', '0', '0', '0']
    
    # \d to match all numbers
    result = re.findall[r"\d+", target_str]
    print[result]
    # Output ['8000']
    
    # \D to match non-digits
    result = re.findall[r"\D", target_str]
    print[result]
    # Output [' ', 'd', 'o', 'l', 'l', 'a', 'r']
    5 khớp với bất kỳ chữ cái viết thường nào từ A đến Z
  • import re
    
    target_str = "Jessa and Kelly!!"
    
    # \w to match all alphanumeric characters
    result = re.findall[r"\w", target_str]
    print[result]
    # Output ['J', 'e', 's', 's', 'a', 'a', 'n', 'd', 'K', 'e', 'l', 'l', 'y']
    
    # \w{5} to 5-letter word
    result = re.findall[r"\w{5}", target_str]
    print[result]
    # Output ['Jessa', 'Kelly']
    
    # \W to match NON-alphanumeric
    result = re.findall[r"\W", target_str]
    print[result]
    # Output [' ', ' ', '!', '!']
    1 khớp với bất kỳ chữ hoa nào từ a đến z
  • ['o', 'e', 'o', 'a', 'a', 'e']
    24 khớp với bất kỳ chữ số nào từ 2 đến 6

Bạn cũng có thể đặt các phạm vi khác nhau bên cạnh nhau trong lớp để tăng thêm khả năng phù hợp.

Ví dụ:

['o', 'e', 'o', 'a', 'a', 'e']
28 sẽ khớp với bất kỳ chữ cái nào của bảng chữ cái: A đến Z [chữ thường] hoặc A đến Z [chữ hoa].

Example:

['o', 'e', 'o', 'a', 'a', 'e']
1

Các lớp nhân vật trong Python là gì?

Một "lớp ký tự", hoặc một "bộ ký tự", là một tập hợp các ký tự được đặt trong dấu ngoặc vuông. Động cơ Regex chỉ khớp với một trong số một số ký tự trong lớp ký tự hoặc bộ ký tự. Chúng tôi đặt các nhân vật chúng tôi muốn phù hợp giữa dấu ngoặc vuông.a set of characters put in square brackets. The regex engine matches only one out of several characters in the character class or character set. We place the characters we want to match between square brackets.

Lớp nhân vật là gì?

Trong bối cảnh của các biểu thức chính quy, một lớp ký tự là một tập hợp các ký tự được đặt trong dấu ngoặc vuông.Nó chỉ định các ký tự sẽ khớp thành công một ký tự từ một chuỗi đầu vào đã cho.a set of characters enclosed within square brackets. It specifies the characters that will successfully match a single character from a given input string.

Nhân vật được đặt trong Python là gì?

Một bộ ký tự là một tập hợp các ký tự hợp lệ được chấp nhận bởi một ngôn ngữ lập trình trong tập lệnh.Trong trường hợp này, chúng ta đang nói về ngôn ngữ lập trình Python.Vì vậy, bộ ký tự Python là một tập hợp các ký tự hợp lệ được nhận ra bởi ngôn ngữ Python.a set of valid characters acceptable by a programming language in scripting. In this case, we are talking about the Python programming language. So, the Python character set is a valid set of characters recognized by the Python language.

Nhân vật đặc biệt Python là gì?

Trong các chuỗi Python, dấu gạch chéo ngược "\" là một nhân vật đặc biệt, còn được gọi là nhân vật "Escape".Nó được sử dụng để thể hiện các ký tự khoảng trắng nhất định: "\ t" là một tab, "\ n" là một dòng mới và "\ r" là một sự trở lại vận chuyển.Ngược lại, tiền tố một ký tự đặc biệt với "\" biến nó thành một ký tự thông thường.backslash "\" is a special character, also called the "escape" character. It is used in representing certain whitespace characters: "\t" is a tab, "\n" is a newline, and "\r" is a carriage return. Conversely, prefixing a special character with "\" turns it into an ordinary character.

Bài Viết Liên Quan

Chủ Đề