Java tutorial
//package com.java2s; //License from project: Apache License import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static final Pattern pagePattern = Pattern.compile("(.*(?:\\?|&)page=)(\\d*)(.*)"); public static String getQueryPageUrl(String url, int inc) { if (url == null) { return null; } if (!url.contains("nicovideo.jp/search/")) { return null; } String ret = null; Matcher matcher = pagePattern.matcher(url); if (matcher.find()) { String _u1 = matcher.group(1); String _p = matcher.group(2); String _u2 = matcher.group(3); int page = 1; try { page = Integer.parseInt(_p) + inc; } catch (NumberFormatException e) { } if (0 < page) { ret = _u1 + page + _u2; } } else { int page = 1 + inc; if (0 < page) { if (url.contains("?")) { ret = url + "&page=" + page; } else { ret = url + "?page=" + page; } } } return ret; } }