regex - Java Regular expression special charecters -


i want replace xx* x.

i tried string.replaceall("xx*", "x");

but in regex * special need give \* give \ in java need give \\

==> should work string.replaceall("xx\\*", "x");

but when string contains xx* above statement fails in replacing xx* x

please thank you

  1. you have reassign result of replaceall() call string variable - method returns new string opposed modifying string call on.

  2. don't use replaceall()!! use replace() when dealing literal strings:

    string = string.replace("xx*", "x"); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -