java 正则表达式
package com.project.utils; import org.apache.commons.lang.StringUtils; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ContentUtils { public static void main(String[] args) { getPageId("https://www.cnblogs.com/alibai/p/topicId=123456789/topicId=12345678/topicId=1234567"); } public static String getPageId(String url) { System.out.println(url); String pageId = ""; if (StringUtils.isBlank(url)) { return pageId; } Pattern pattern = Pattern.compile("topicId=\d+"); Matcher matcher = pattern.matcher(url); if (matcher.find()) { pageId = matcher.group().split("topicId")[1]; } while (matcher.find()){ System.out.println(matcher.group()); } return pageId; } }