Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

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

Shulou Source: shulou.com Published: 2022-06-02 06:22:41 10月03日 Update

This article mainly explains the "JS, replace how to use regular expressions to replace all the parameters of SQL for the specified format of data", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "JS, replace how to use regular expressions to replace all parameters of SQL to the specified format of data" it!

SQL parameter format for example: select * from tb where nd=:nd and yd=:yd

Want to replace all parameters (with colons) in SQL statements into data at once

Start

Choose to use regular expressions.

It was written like this before.

The copy code is as follows:

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

"$1" is always resolved to a string rather than a matching value

Replace it with

The copy code is as follows:

Strsql.replace (/ (:\ w +) / gjingo 1)

Can not give a matching value, $1 to get a matching value must be enclosed in double quotes.

Then a method was added to the whim.

Pass $1 as a parameter, as follows

The copy code is as follows:

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

Thank you for your reading, the above is the "JS, replace how to use regular expressions to replace all parameters of SQL for the specified format of data" of the content, after the study of this article, I believe you on JS, replace how to use regular expressions to replace all parameters of SQL for the specified format of data have a deeper understanding of the problem, the specific use of the need for you to practice verification. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Parameters codes data formats regularities expressions learning content one-time colons whims characters strings that is quotes ideas situations ideas articles methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information vpn MySQL Xiaomi MariaDB