regex - Java Regular Expression not working (but does at Rubular) -


at rubular testing regular expression:

(\d+).html 

test string:

"/magnoliaauthor/services/services/07.html" 

just needed, returned "07" first match group. perfect. need regex in java environment, wrote piece of code:

import java.util.regex.*;  class main {   public static void main (string[] args)    {     string jcrpath = "/magnoliaauthor/services/services/07.html";     pattern pattern = pattern.compile("(\\d+).html");     matcher matcher = pattern.matcher(jcrpath);     system.out.println(matcher.group());   } } 

as explained here, added anothere \ regex. sadly me, when compiling , running code, following exception: java.lang.illegalstateexception: no match found

does know why there aren't matches?

you need apply pattern, too:

pattern pattern = pattern.compile("(\\d+)\\.html"); // compiles regex matcher matcher = pattern.matcher(jcrpath);         // creates matcher object  if (matcher.find()) {                               // performs actual match     system.out.println(matcher.group()); } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -