Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I tried to formulate my version of url. My requirement was to capture instances in a String where possible url can be cse.uom.ac.mu - noting that it is not preceded by http nor www</p> <pre><code>String regularExpression = "((((ht{2}ps?://)?)((w{3}\\.)?))?)[^.&amp;&amp;[a-zA-Z0-9]][a-zA-Z0-9.-]+[^.&amp;&amp;[a-zA-Z0-9]](\\.[a-zA-Z]{2,3})"; assertTrue("www.google.com".matches(regularExpression)); assertTrue("www.google.co.uk".matches(regularExpression)); assertTrue("http://www.google.com".matches(regularExpression)); assertTrue("http://www.google.co.uk".matches(regularExpression)); assertTrue("https://www.google.com".matches(regularExpression)); assertTrue("https://www.google.co.uk".matches(regularExpression)); assertTrue("google.com".matches(regularExpression)); assertTrue("google.co.uk".matches(regularExpression)); assertTrue("google.mu".matches(regularExpression)); assertTrue("mes.intnet.mu".matches(regularExpression)); assertTrue("cse.uom.ac.mu".matches(regularExpression)); //cannot contain 2 '.' after www assertFalse("www..dr.google".matches(regularExpression)); //cannot contain 2 '.' just before com assertFalse("www.dr.google..com".matches(regularExpression)); // to test case where url www must be followed with a '.' assertFalse("www:google.com".matches(regularExpression)); // to test case where url www must be followed with a '.' //assertFalse("http://wwwe.google.com".matches(regularExpression)); // to test case where www must be preceded with a '.' assertFalse("https://www@.google.com".matches(regularExpression)); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload