1

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
  • 389
  • 5
  • 13

3 Answers3

7

You can add i flag for ignore case matching:

/(^|<|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|>|$)/ig
anubhava
  • 761,203
  • 64
  • 569
  • 643
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.
  • 35,491
  • 6
  • 51
  • 50
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,462
  • 3
  • 14
  • 25