Avatar of Stephen Forlance
Stephen Forlance
 asked on

Javascript Regex

Hello all,
Im trying to create a function that would search through a string and then replace :something with '$something'

For example:
select * from internal where id = :id and name=:kn_op_id

would result in

select * from internal where id = '$id' and name='$kn_op_id'

Can anyone help?
JavaScriptRegular Expressions

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
SOLUTION
Rgonzo1971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Stephen Forlance

ASKER
Hi, for the first match its actually coming back as id = '$1' instead of $id
ASKER CERTIFIED SOLUTION
Dan Craciun

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Julian Hansen

Why have you posted this to the JavaScript Topic Area - is there a JavaScript component to it - looks more like MySQL / PHP
Dan Craciun

@Julian: that's plain SQL.
If the OP wants to modify SQL queries using JS, where is the problem?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Stephen Forlance

ASKER
Julian - its a javascript question regarding regex manipulation of a string.
Julian Hansen

@Dan,

Just trying to establish what the background is - when you see an SQL query with $ variables (PHP) in a JavaScript context it raises questions - I was just making sure I completely understand the context before attempting a solution.