JS Replace full Replace characters usage summary

  • 2020-03-30 01:01:52
  • OfStack

Script language = "javascript" >
Var r = "1, n2 and n3 \ n";
// replace the element number with the letter \n
Alert (r.r eplace (" \ n ", ";" ));

Results: 1; 2\n3\n just replaced the first one
< / script>

< Script language = "javascript" >
Var r = "1, n2 and n3 \ n";
// replace the element number with the letter \n
Alert (r.r eplace (\ n/g, ";" ));

Results: 1; 2; 3; The first parameter of replace can be a regular expression, and /g identifies a full-text match.
< / script>


Related articles: