Regular Expression replace

Source: Internet
Author: User
String. Prototype. Trim = function ()
{
// Use a regular expression to separate spaces
// Replace it with a null string.
Return this. Replace (/(^/S *) | (/S * $)/g ,"");
}

// A string with spaces
VaR S = "Leading and trailing spaces ";

// Display "Leading and trailing spaces (35 )"
Window. Alert (S + "(" + S. Length + ")");

// Delete leading and trailing Spaces
S = S. Trim ();
// Display "Leading and trailing spaces (27 )"
Window. Alert (S + "(" + S. Length + ")");

How to replace @ aab_aa with @ aab_aa_1
@ Aab_aa is variable.
Is how to find the string starting with @, ending with a non-letter number and "_", and replace the content of the string with + "_ 1"
String S = "AFAS + @ aab_aa + 5 ";
Console. writeline (RegEx. Replace (S, "(@ [0-9a-za-z _] +)", "$1_1 "));
String S = "AFAS + @ aab_aa + 5 + @ aab_aaccc ";
Assume that @ aab_aa is fixed. How can I ensure that @ aab_aaccc is not replaced?
Console. writeline (RegEx. Replace (S, "(@ aab_aa +) ([^ 0-9a-za-z _] +)", "$1_1 $2 "));

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.