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.
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.
You can add i flag
for ignore case matching:
/(^|<|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|>|$)/ig
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));
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.