0

Actually I've used regex pattern on url to replace its string. I tried to replace the "www." from the url. Now, I would like to know that is there any benefit or problem to use regex pattern instead to put that exact string.

For example, sting.replace("/w{3}./","") vs string.replace("www.","");

I am asking about the topic like execution time.

4
  • 1
    Which language? Also, please include valid syntax.. Anyway, generally one would use a regular expression when a literal string replacement wouldn't work. The biggest downside of a regular expression, IMOHO, is accidental forgetting to escape special characters (as shown) - especially if it comes from user input. "Performance" is usually irrelevant. Commented Jun 22, 2015 at 4:53
  • 1
    string.replace won't take regex as an argument. Commented Jun 22, 2015 at 4:54
  • 1
    hmm the . in question would be a metacharacter if not escaped :) Commented Jun 22, 2015 at 4:56
  • For .net, stackoverflow.com/questions/1620410/… Commented Jun 22, 2015 at 5:21

0

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.