regex - Java RegExp Underscore -


i want replace content (double underscores left , right, see code) in given string, can't work. this:

string test = "hello! content: __content__"; test.replaceall("__content__", "yeah!"); system.out.println("output: " + test); 

so output should be: "output: hello! content: yeah!" regular expression in first parameter of replaceall wrong, don't know correct one. knows how?

you forgot assign return value of replaceall original string. replaceall (or other string method) doesn't change original string:

string test = "hello! content: __content__"; test = test.replaceall("__content__", "yeah!"); system.out.println("output: " + test); 

btw don't need regex here, use replace:

test = test.replace("__content__", "yeah!"); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

spring cloud - How to configure SpringCloud Eureka instance to point to https on non standard port -

javascript - Bootstrap Popover: iOS Safari strange behaviour -