PatternMatcher

Run Settings
LanguageJava
Language Version
Run Command
import java.util.regex.Matcher; import java.util.regex.Pattern; class PatternMatcher { public static void main(String[] args) { String[] urls = {"https://example.com/articles/0ba08991-d85d-4236-8820-d49d588c26bf", "https://example.com/articles/6ae9ef81-40a6-4528-81f4-d690ab08aacd/comment", "https://example.com/articles/e727c2c9-3434-4572-8c9c-a2bd81c74356/publish", "https://example.com/artifcles/" }; Pattern p = Pattern.compile(".*/articles/(?<guid>[0-9a-f-]+)(?:/(?<method>.*))?$"); System.out.println("p: [" + p + "]\n"); for (String url : urls) { Matcher m = p.matcher(url); System.out.print("url: [" + url + "] "); if (m.matches()) { System.out.println("✓"); System.out.println("\tguid: [" + m.group("guid") + "]"); System.out.println("\tmethod: [" + m.group("method") + "]"); System.out.println("\tThis is" + ("comment".equals(m.group("method")) ? " " : " not ") + "a comment"); } else { System.out.println("(does not match)"); } } } }
Editor Settings
Theme
Key bindings
Full width
Lines