Link to home
Start Free TrialLog in
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?
SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stephen Forlance
Stephen Forlance

ASKER

Hi, for the first match its actually coming back as id = '$1' instead of $id
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why have you posted this to the JavaScript Topic Area - is there a JavaScript component to it - looks more like MySQL / PHP
@Julian: that's plain SQL.
If the OP wants to modify SQL queries using JS, where is the problem?
Julian - its a javascript question regarding regex manipulation of a string.
@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.