Home > DeveloperSection > Forums > Java String/Regex Replace
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    May-15-2013 8:05 AM

 Java Java 
Ratings:


 1 Reply(s)
 891  View(s)
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! 


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-15-2013 8:52 AM

Hi Ankita!

Use the \b (word boundary) operator

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

Don't want to miss updates? Please click the below button!

Follow MindStick