JS How to replace the characters in a string replace

Source: Internet
Author: User

Grammar
Stringobject.replace (regexp/substr,replacement) parameter description
Regexp/substr required. The RegExp object that prescribes the substring or pattern to be replaced.

<script type= "text/web Effects" >
var str= "Visit 111cn.net!"
document.write (Str.replace (/111cn.net/, "111cn.net"))
</script>


To modify the size of a picture:

Replace the size in the picture properties with the following statement.

$ ("image"). attr ("src"). Replace ("size=60", "size=200");

Replace (target to replace, new value to replace)


Definitions and usage


Note that if the value is a string, it is used as the direct text pattern to retrieve, not first converted to the RegExp object.

Replacement required. A string value. Provides a function that replaces text or generates alternate text.

return value
A new string that is replaced with replacement for the first match of RegExp or after all matches have been made.

Description
The replace () method of the string Stringobject performs a find-and-replace operation. It will look for substrings in the stringobject that match the regexp, and then replace them with replacement. If RegExp has global flag G, then the Replace () method replaces all matching substrings. Otherwise, it replaces only the first matching substring.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.