hi ii want to select links that are lin this format: *[. or /]mydomain.com for example select http://mydomain.com http://subdomain.mydomain.com and http://www.mydomain.com and http://www.subdomain.mydomain.com in this case: a[href *= 'mydomain.com'] it select site like xyzmydomain.com too
i think you can't select href values like regex does.. what you can do is to select all <a> the test each of it inside .each();
thank you for your reply i found this : http://forum.jquery.com/topic/regex-in-jquery but https?:\/\/(\w+).example.(\w+) doesn't work for me only select urls like http://www.mydomain.com and https://www.mydomain.com and doesn't select http://mydomain.com or http://www.subdomain.mydomain.com so i change it to /https?:\/\/(\w*)(\.*)(\w*)(\.*)example.(\w+)/; now it select all of types BUT if url be like this: http://subdomain[dot]subdomain[dot]subdomain.example.com it doesn't work is there any regex pattern that include all characters? (\w+) do not include [dot] my english is poor
Will this help? $.fn.replaceUrl = function() { var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi; this.each(function() { $(this).html( $(this).html().replace(regexp,'<a href="$1">$1</a>‘) ); }); return $(this); } //usage $('p').replaceUrl(); Code (markup): http://addyosmani.com/blog/50-jquery-snippets-for-developers/
thank you so much var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S*)(:[0-9]*)?example.(\w+)/; Code (markup):
Now i have new problem in this code <li>fdsafdsa <a href =http://www.example.com>salam1</a>fdsafdsafdsa </li> <a href =http://www.example.com>salam1</a> Code (markup): i want to hide ONLY li elements that contains *a* tag when i use this code $("li:has(a)").css('display', function() { var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S*)(:[0-9]*)?(example.)(\w*)/; if(regexp.test(this.href)) return 'none'; return 'inline'; }); Code (markup): it doesn't work because this.href refer to li tag i want to refer to a tag any solution? that's better to use hide function in jquery instead use display property to hide it