What happened to this regex?

I am trying to use the following Java code:

String test = "http://asda.aasd.sd.google.com/asdasdawrqwfqwfqwfqwf";
String regex = "[http://]{0,1}([a-zA-Z]*.)*\\.google\\.com/[-a-zA-Z/_.?&=]*";
System.out.println(test.matches(regex));

It works for several minutes (after that I killed the virtual machine) with no result. Can anybody help me?

BTW: What would you advise me to do to speed up weblink-testng regular expressions?

+3
source share
6 answers

[http://] is a character class meaning any of these characters in a set.

Just leave these square brackets if it should start with http://. If this is optional, you can use (http://)?.

, ([a-zA-Z]+.)*\\.google - - ., " ", , .

, , ([a-zA-Z]+\\.)*\\.google, - . google. :

String regex = "(http://)?([a-zA-Z]+\\.)*google\\.com/[-a-zA-Z/_.?&=]*";

true.

, / google.com. , , , .

+7

, . . . {0,1}, ?.

, google\\.com, . cherouvim, .

String regex = "(http://)?([a-zA-Z]+\\.)*google\\.com/[-a-zA-Z/_.?&=]*";
+4

([a-zA-Z]*.) . ( " " ), .

+3

.

, . "http://" , . .

. , .

, , - , , . , . "google", "http://google.com/etc" ( , Google).

, :

String regex = "(http://){0,1}([a-zA-Z]+\\.)*google\\.com/[-a-zA-Z/_.?&=]*";

.

+2

, ([a-zA-Z]*\\.), * +, ([a-zA-Z]+\\.). http://...google.com, .

+1

google.com, , URL. , rexep - , URL- Java. getHost(). , google.com, .

URL url = new URL("http://asda.aasd.sd.google.com/asdasdawrqwfqwfqwfqwf");
String host = url.getHost();
if (host.endsWith("google.com"))
    {
    String [] parts = host.split("\\.");
    for (String s: parts)
        System.out.println(s);
    }
+1

Source: https://habr.com/ru/post/1773197/


All Articles