We help IT Professionals succeed at work.

Javascript Regex

133 Views
Last Modified: 2018-07-18
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?
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Hi, for the first match its actually coming back as id = '$1' instead of $id
IT Consultant
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
Why have you posted this to the JavaScript Topic Area - is there a JavaScript component to it - looks more like MySQL / PHP
Dan CraciunIT Consultant
CERTIFIED EXPERT

Commented:
@Julian: that's plain SQL.
If the OP wants to modify SQL queries using JS, where is the problem?

Author

Commented:
Julian - its a javascript question regarding regex manipulation of a string.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
@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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions