0

I have the below in javascript, it works for this case;

http://www.google.com


/(^|<|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|>|$)/g

but it fails for this:

Http://www.google.com

is there a way to make my statement case insensitive.

Rafa Tost
  • 379
  • 5
  • 13

3 Answers3

6

You can add i flag for ignore case matching:

/(^|<|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|>|$)/ig
anubhava
  • 713,503
  • 59
  • 514
  • 593
1

Even though the votes are in for adding the i flag (which is a perfectly valid solution), I would point out that it is a bit more efficient to leave your regex as is and call toLowerCase() on your string prior to running it through the regex IFF that is an option.

var uri = "Http://www.GooGlE.cOm";
console.log(uri.toLowerCase().match(/(^|<|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|>|$)/g));
Rob M.
  • 33,381
  • 6
  • 50
  • 46
0

use following line

/(^|<|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|>|$)/i

/g enables "global" matching. When using the replace() method, specify this modifier to replace all matches, rather than only the first one. /i makes the regex match case insensitive. /m enables "multi-line mode". In this mode, the caret and dollar match before and after newlines in the subject string.

Indranil.Bharambe
  • 1,442
  • 3
  • 14
  • 25