I need to regularize url with many cases in java.
- custom1://www.test.com:6666/path1/path2
- custom2://www.test.com/path1/path2
- custom3://www.test.com
- www.test.com:6666
- www.test.com:666
if this case, what can i use regex..?
I need to regularize url with many cases in java.
if this case, what can i use regex..?
You are saying custom URL
first of all this is not a clear statement, you should be more clear, in normal case ^(https?|chrome):\/\/[^\s$.?#].[^\s]*$
this regex string should get the job done for you.
for matching only URLs using regular expressions, you can use the regex above
String regex = "((http|https)://)(www.)?"
+ "[a-zA-Z0-9@:%._\\+~#?&//=]"
+ "{2,256}\\.[a-z]"
+ "{2,6}\\b([-a-zA-Z0-9@:%"
+ "._\\+~#?&//=]*)";
I found this here
I think this should work just modified little from amireza's answer to add custom also after https or http
String regex = "(http|https)"
+ "[a-zA-Z0-9]"
+ "(://)(www.)?"
+ "[a-zA-Z0-9@:%._\\+~#?&//=]"
+ "{2,256}\\.[a-z]"
+ "{2,6}\\b([-a-zA-Z0-9@:%"
+ "._\\+~#?&//=]*)";