JAVA STRING/REGEX REPLACE

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
Java 
 1150  View(s)
Ratings:
Rate this:
Hi!

I'm quite new to regex. Not sure how to do the follow:

Replace ":p_id" with a specific value.

For example when I simply want to replace ":p_id1" with a value, it also replaced ":p_id10" with the same value which is not what I want.

It's also possible for the ":p_id"'s to have punctuation before or after them e.g. "=:p_id1)"

Any advice?
Thanks in advance! 
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Java String/Regex Replace

    Hi Ankita!

    Use the \b (word boundary) operator

    myString.replaceAll(":p_id1\\b","some replacement");

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!