Internalhtml thay thế tất cả

Phương thức

function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
1 trả về một chuỗi mới với tất cả các kết quả khớp của một
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
2 được thay thế bằng một
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
3.
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
2 có thể là một chuỗi hoặc một
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
0 và
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
3 có thể là một chuỗi hoặc một hàm được gọi cho mỗi trận đấu. Chuỗi ban đầu không thay đổi

Thử nó

cú pháp

replaceAll[pattern, replacement]

Thông số

function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
2

Có thể là một chuỗi hoặc một đối tượng có phương thức

function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
3 — ví dụ điển hình là một biểu thức chính quy. Bất kỳ giá trị nào không có phương thức
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
3 sẽ bị ép thành một chuỗi

Nếu

function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
2 là một biểu thức chính quy, thì nó phải có cờ toàn cầu [
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
6] được đặt hoặc một
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
7 được ném ra

function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
3

Có thể là một chuỗi hoặc một chức năng. Sự thay thế có cùng ngữ nghĩa như của

function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
9

Giá trị trả về

Một chuỗi mới, với tất cả các kết quả khớp của một mẫu được thay thế bằng một chuỗi thay thế

ngoại lệ

function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
7

Bị ném nếu

function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
2 là một biểu thức chính quy không có cờ toàn cầu [
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
6] được đặt [thuộc tính
"xxx".replaceAll["", "_"]; // "_x_x_x_"
3 của nó không chứa
"xxx".replaceAll["", "_"]; // "_x_x_x_"
4]

Sự mô tả

Phương thức này không làm thay đổi giá trị chuỗi mà nó được gọi. Nó trả về một chuỗi mới

Không giống như

"xxx".replaceAll["", "_"]; // "_x_x_x_"
5, phương pháp này sẽ thay thế tất cả các lần xuất hiện của một chuỗi, không chỉ lần xuất hiện đầu tiên. Điều này đặc biệt hữu ích nếu chuỗi không được biết tĩnh, vì việc gọi hàm tạo
"xxx".replaceAll["", "_"]; // "_x_x_x_"
6 mà không thoát các ký tự đặc biệt có thể vô tình thay đổi ngữ nghĩa của nó

function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."

Nếu

function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
2 là đối tượng có phương thức
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
3 [bao gồm đối tượng
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
0], thì phương thức đó được gọi với chuỗi đích và đối số
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
3. Giá trị trả về của nó trở thành giá trị trả về của
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
1. Trong trường hợp này, hành vi của
function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
1 được mã hóa hoàn toàn bằng phương pháp
replaceAll[pattern, replacement]
63 và do đó sẽ có kết quả tương tự như
"xxx".replaceAll["", "_"]; // "_x_x_x_"
5 [ngoài xác thực đầu vào bổ sung rằng biểu thức chính quy là toàn cầu]

Nếu

function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
2 là một chuỗi rỗng, chuỗi thay thế sẽ được chèn vào giữa mỗi đơn vị mã UTF-16, tương tự như hành vi của
replaceAll[pattern, replacement]
66

"xxx".replaceAll["", "_"]; // "_x_x_x_"

Để biết thêm thông tin về cách các thuộc tính regex [đặc biệt là cờ cố định] tương tác với

function unsafeRedactName[text, name] {
  return text.replace[new RegExp[name, "g"], "[REDACTED]"];
}
function safeRedactName[text, name] {
  return text.replaceAll[name, "[REDACTED]"];
}

const report =
  "A hacker called ha.*er used special characters in their name to breach the system.";

console.log[unsafeRedactName[report, "ha.*er"]]; // "A [REDACTED]s in their name to breach the system."
console.log[safeRedactName[report, "ha.*er"]]; // "A hacker called [REDACTED] used special characters in their name to breach the system."
1, hãy xem
replaceAll[pattern, replacement]
68

Chủ Đề