0

I have two replace methods called on a string, and I know they can be combined. I would like to know how to combine the two expressions, why, and maybe links to more information

var key = templateKey.replace(/:/g, '').replace(/\//g,'')
0

2 Answers 2

2

Well, Dr. Google can give you lots of links for more information on regular expressions, but in this case you're just replacing either a colon (:) or a slash (/), so you could combine them using the OR (|) grouping:

/(:|\/)/
Sign up to request clarification or add additional context in comments.

2 Comments

So much information on google for regex! It's been a real challenge for me to pick up. The "Or" operator and grouping is exactly the information I wanted to know! exp +50, regex lvl ++. The "more resources" request was in hopes someone had an idiots guide to regex basics laying around.
btw, ateich's answer is also correct (it gets an upvote from me).
1
var key = templateKey.replace(/[:\/]/g, '');

2 Comments

Can i get some explanation for this expression?
@TheodoreEnderby read this answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.