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

c# - IMAP GMAIL getting folder list problem -

PHP proxy to get XML: problem with URL arguments -