JS and replace use regular expressions to replace all SQL parameters with data in the specified format

Source: Internet
Author: User
JavaScript and replace convert all SQL parameters (with colons) into data using regular expressions at a time. The specific implementation ideas and code are as follows. If you are interested, refer to the following, I hope to help you with the SQL parameter format, for example: select * from tb where nd =: nd and yd =: yd
To replace all parameters (with colons) in all SQL statements with data at one time,

Start
Select a regular expression.

Originally written like this

Strsql. replace (/(: \ w +)/g, ("$1"). substring (1 ));

"$1" is always parsed as a string instead of a matching value.
Change

Strsql. replace (/(: \ w +)/g, $1 );

No matching value is provided. To get a matching value, $1 must contain double quotation marks.

Then a method was added to the whimsy.
Pass $1 as a parameter, as shown below

Var strsql = strsql. replace (/(: \ w +)/g, function ($1) {var B = $1; return $ ("#" + B. substring (1 )). val ();});


For more articles about replacing all SQL parameters in the specified format with regular expressions in JS and replace, please refer to PHP!

Related Article

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.