如何在php中向正则表达式模式的caputure添加括号?
我想给字符串中的变量添加括号。如何使用正则表达式在php上实现它 字符串:如何在php中向正则表达式模式的caputure添加括号?,php,regex,Php,Regex,我想给字符串中的变量添加括号。如何使用正则表达式在php上实现它 字符串: UPDATE item_tbl SET name='$name',code='$code',category_fk=$category_fk,modified_by_fk=$modified_by_fk,price=$price 正则表达式模式: /\$(\w*)/g 输出: updateitem\u tbl SET name=”($name)”、code=”($code)”、category\u fk=($catego
UPDATE item_tbl SET name='$name',code='$code',category_fk=$category_fk,modified_by_fk=$modified_by_fk,price=$price
正则表达式模式:
/\$(\w*)/g
输出:
updateitem\u tbl SET name=”($name)”、code=”($code)”、category\u fk=($category\u fk)、modified\u by\u fk=($modified\u by\u fk)、price=($price)
您可以尝试以下方法:
(\$\w+)
并替换为:
($1)
样品溶液()
样本输出:
UPDATE item_tbl SET name = '($name)',code = '($code)',category_fk = ($category_fk),modified_by_fk = ($modified_by_fk),price = ($price)
UPDATE item_tbl SET name = '($name)',code = '($code)',category_fk = ($category_fk),modified_by_fk = ($modified_by_fk),price = ($price)