Remove part of string that matches text in a variable

I need to remove part of a string that matches the text in a variable. Essentially, I need something like this: $('text').value = $('text').value.replace(/pin,/, '') where pin is a variable containing eight numeric characters and a comma (e.g. 12345678,). $('text').value is a comma-delimited list of PINs.

Thanks.
Shiseiryu1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
Try:
Single replacement:
$('text').value = $('text').value.replace(/\d{8}[,]/, '')

OR:
Global Replacement:
$('text').value = $('text').value.replace(/\d{8}[,]/g, '')
0
b0lsc0ttIT ManagerCommented:
Shiseiryu1,

If the number is specific then you would need to do something like ...

myregex = new Regexp(variable);
$('text').value = $('text').value.replace(myregex, "");

The "variable" in the first line could be the specific number/comma value you want to remove.  One caution, that "string" would need to be escaped in certain cases but this won't be an issue if you just have numbers and a comma.

Let me know if you have any questions or need more information.

b0lsc0tt
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shiseiryu1Author Commented:
Thanks much, b0lsc0tt, that did the trick. I would just add for those who may run across this solution in a search that "Regexp" seems to require intercaps to work correctly, so it has to be "RegExp".

Thanks again!
0
b0lsc0ttIT ManagerCommented:
Your welcome!  Good catch and thanks for pointing it out on the spelling error.  Case definitely is important in Javascript and it should've been RexExp.

Thanks for the grade, the points and the fun question.

bol
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.