-3

I need to regularize url with many cases in java.

if this case, what can i use regex..?

ew2
  • 25
  • 4

3 Answers3

0

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.

Aziz Gasimov
  • 66
  • 3
  • 13
0

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

amireza gh
  • 19
  • 2
0

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@:%"
          + "._\\+~#?&//=]*)";