regex - Java Regular Expressions -


i trying write this:

pattern p = pattern.compile("mar\\w"); matcher m = p.matcher("mary");  string result = m.replaceall("\\w"); 

the result ideally "y". ideas?

your question not clear, think want use lookahead:

pattern p = pattern.compile("mar(?=\\w)"); matcher m = p.matcher("mary"); string result = m.replaceall(""); 

see online: ideone

or use capturing group:

pattern p = pattern.compile("mar(\\w)"); matcher m = p.matcher("mary"); string result = m.replaceall("$1"); 

see online: ideone


Comments

Popular posts from this blog

jQuery clickable div with working mailto link inside -

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -