---
title: "Java String/Regex Replace"  
description: "Java String/Regex Replace"  
author: "Anonymous User"  
published: 2013-05-15  
updated: 2013-05-15  
canonical: https://www.mindstick.com/forum/887/java-string-regex-replace  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Java String/Regex Replace

Hi!\
I'm quite new to regex. Not sure how to do the follow:\
[Replace](https://yourviews.mindstick.com/view/81330/cow-antibody-research-in-usa-a-step-ahead-to-replace-plasma-therapy) ":p_id" with a specific [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages).\
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](https://yourviews.mindstick.com/view/50528/filament-advice-5-things-to-consider-before-you-buy-a-filament)?Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Ankita!\
Use the \b (word boundary) operator\
myString.replaceAll(":p_id1\\b","some replacement");


---

Original Source: https://www.mindstick.com/forum/887/java-string-regex-replace

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
