Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is an all regex solution.</p> <p><strong>Edit:</strong> Allows for http://</p> <p><strong>Java source:</strong></p> <pre><code>import java.util.*; import java.lang.*; import java.util.regex.*; class Main { public static void main (String[] args) throws java.lang.Exception { String url = "http://www.examplesite.com/dir/2012/06/19/title-of-some-story/FAQKZjC3veXSalP9zxFgZP/htmlpage.html"; String url2 = "www.examplesite.com/dir/dir2/dir3/2012/06/19/FAQKZjC3veXSalP9zxFgZP/htmlpage.html"; String url3 = "www.examplesite.com/2012/06/19/title-of-some-story/FAQKZjC3veXSalP9zxFgZP/htmlpage.html"; String patternStr = "(?:http://)?[^/]*[/]?([\\S]*)/[\\d]{4}/[\\d]{2}/[\\d]{2}[/]?([\\S]*)/[\\S]*/[\\S]*"; // Compile regular expression Pattern pattern = Pattern.compile(patternStr); // Match 1st url System.out.println("Match 1st URL:"); Matcher matcher = pattern.matcher(url); if (matcher.find()) { System.out.println("URL: " + matcher.group(0)); System.out.println("DIR: " + matcher.group(1)); System.out.println("TITLE: " + matcher.group(2)); } else{ System.out.println("No match."); } // Match 2nd url System.out.println("\nMatch 2nd URL:"); matcher = pattern.matcher(url2); if (matcher.find()) { System.out.println("URL: " + matcher.group(0)); System.out.println("DIR: " + matcher.group(1)); System.out.println("TITLE: " + matcher.group(2)); } else{ System.out.println("No match."); } // Match 3rd url System.out.println("\nMatch 3rd URL:"); matcher = pattern.matcher(url3); if (matcher.find()) { System.out.println("URL: " + matcher.group(0)); System.out.println("DIR: " + matcher.group(1)); System.out.println("TITLE: " + matcher.group(2)); } else{ System.out.println("No match."); } } } </code></pre> <p><strong>Output:</strong></p> <pre><code>Match 1st URL: URL: http://www.examplesite.com/dir/2012/06/19/title-of-some-story/FAQKZjC3veXSalP9zxFgZP/htmlpage.html DIR: dir TITLE: title-of-some-story Match 2nd URL: URL: www.examplesite.com/dir/dir2/dir3/2012/06/19/FAQKZjC3veXSalP9zxFgZP/htmlpage.html DIR: dir/dir2/dir3 TITLE: Match 3rd URL: URL: www.examplesite.com/2012/06/19/title-of-some-story/FAQKZjC3veXSalP9zxFgZP/htmlpage.html DIR: TITLE: title-of-some-story </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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