Java String/Regex Replace

Total Post:183


 1650  View(s)
Rate this:

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. Re: Java String/Regex Replace

    Hi Ankita!

    Use the \b (word boundary) operator

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


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.