Neighborhoods with a regular expression string replacement

Category: Java EE
2009-04-04 03:41:24

Sponsored Links
For example, there is a string: p1 + p11

now I want to use 5, replace p1.

correct result is: 5 + p11

I use the replace method to be replaced, can result is: 5 +51

Please help solve this problem. I heard that regular expressions can be resolved, if the line, please write detailed process.

if there are other ways also.

Sponsored Links

2009-04-04 03:47:13
try ...

String test = "p1+p11";
String result = test.replaceAll("\\bp1\\b", "5");
2009-04-04 03:58:31

String test = "p1+p11";
  String result = test.replaceAll("p1(?!\\d+)", "5");
2009-04-04 04:13:20
Or the learn more regex
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.