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

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -