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.

Manu
  • 2,251
  • 19
  • 30
GoCool
  • 7
  • 1
  • 8
  • 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. – user2864740 Jun 22 '15 at 04:53
  • 1
    `string.replace` won't take regex as an argument. – Avinash Raj Jun 22 '15 at 04:54
  • 1
    hmm the `.` in question would be a metacharacter if not escaped :) – Pruthvi Raj Jun 22 '15 at 04:56
  • For .net, http://stackoverflow.com/questions/1620410/regex-replace-string-replace-or-stringbuilder-replace-which-is-the-fastest – Manu Jun 22 '15 at 05:21

0 Answers0