Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A naive approach would be to split your URL into groups (say <code>url.split("/")</code>) and compare the resulting arrays. It the parts match, just add them as constant strings to the pattern. If they don't, add a pattern that matches all possible values. Here is a simple implementation:</p> <pre><code>public static void main(String[] args) throws Exception { String[] urls = { "http://www.buy.com/prod/disney-s-star-struck/q/loc/109/213724402.html", "http://www.buy.com/prod/samsung-f2380-23-widescreen-1080p-lcd-monitor-150-000-1-dc-8ms-1920-x/q/loc/101/211249863.html", "http://www.buy.com/prod/panasonic-nnh765wf-microwave-oven-countertop-1-6-ft-1250w-panasonic/q/loc/66357/202045865.html", "http://www.buy.com/prod/escape-by-calvin-klein-for-women-3-4-oz-edp-spray/q/loc/66740/211210860.html", "http://www.buy.com/prod/v-touch-8gb-mp3-mp4-2-8-touch-screen-2mp-camera-expandable-minisd-w/q/loc/111/211402014.html" }; String all = "[^/]+"; String[] pattern = urls[0].split("/"); for (int i = 0; i &lt; urls.length; i++) { String parts[] = urls[i].split("/"); // TODO handle urls with different number of parts for (int j = 0; j &lt; pattern.length; j++) { // intentionally match by reference if (pattern[j] != all &amp;&amp; !pattern[j].equals(parts[j])) { pattern[j] = all; } } } // build pattern - use [^/]+ as a replacement (anything but a '/') StringBuilder buf = new StringBuilder(); for (int i = 0; i &lt; pattern.length; i++) { buf.append(pattern[i] == all ? all : Pattern.quote(pattern[i])); buf.append("/"); } // stip last "/" buf.setLength(buf.length() - 1); // compile pattern Pattern p = Pattern.compile(buf.toString()); // output System.out.println(p.pattern()); for (int i = 0; i &lt; urls.length; i++) { System.out.println(p.matcher(urls[i]).matches()); } } </code></pre> <p>Here's the output of this example:</p> <pre><code>\Qhttp:\E/\Q\E/\Qwww.buy.com\E/\Qprod\E/[^/]+/\Qq\E/\Qloc\E/[^/]+/[^/]+ true true true true true </code></pre> <p>As you see, the pattern looks a bit weird. That's due to the Pattern quoting. Nevertheless, the pattern matches all urls from this example. There's some work left though, most noteably handling urls with different number of parts after split and common suffixes (.html).</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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