java - character getting replaced by using regular expression -
string tempprop="(kfsdk)#"; tempprop = tempprop.replaceall("[^\\s]\\)\\#", "\"?if_exists}"); system.out.println("1"+tempprop+"2");
i want output
1(kfsdk"?if_exists}2
but output of regular expression
1(kfsd"?if_exists}2
last k getting trimmed, , don't know why.
if tempprop ( )#, output should 1( )#2 without "?if_exists regular expression adds "?if_exists
if no space present else returns string is
you use negative lookbehind instead of [^\\s]
because causes effect in final output. is, lookarounds 0 width match.
string tempprop="(kfsdk)#"; tempprop = tempprop.replaceall("(?<!\\s)\\)#", "\"?if_exists}"); system.out.println("1"+tempprop+"2");
output:
1(kfsdk"?if_exists}2
explanation:
(?<!\s)
negative lookbehind asserts preceeds not space character.\)#
matches literal)#
symbols.
Comments
Post a Comment