javascript regular expression

In js, there is a function “replace(source, target)” which means replace the source of original with target.

Wherein source can be a plain string or regular expression, e.g.

var s = " You can click this link to access detail : ${url=http://192.168.0.1/TEST/a?} "; var t = s.replace(/\${url=([^+]+)}/,"");

if source is regular expression :

  • it CANNOT be enclosed by ""
  • regular expression has to be start with / and end with /, while /.../g represents replace all match string
  • $ needs to be escaped, while { or } doesn't
Written on October 19, 2016