replace - JavaScript: Replacing a string containing newlines -
ref: js fiddle
i've <pre> element containing multiple lines inside. using jquery, i'm calling .html() innerhtml, , doing string replace() on returned html string. however, replace works on first line, , fails rest presumably because returned innerhtml has newline.
could suggest workaround having both lines within <pre> replaced?
notice warning using flags parameter in replace function, found @ https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/string/replace:
note: flags argument non-standard mozilla extension. string specifying combination of regular look flags. utilize of flags parameter in string.replace method non-standard. instead of using parameter, utilize regexp object corresponding flags.
(emphasis mine)
so, instead of using parameters, should utilize proper regexes instead:
string = string.replace(/<your-login>/g, username); string = string.replace(/<repository-name>/g, reponame); javascript replace
No comments:
Post a Comment