Java String/Regex Replace
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)"
Use the \b (word boundary) operator
You could use a negative lookahead at the end of your Pattern.
Pattern pattern = Pattern.compile(":p_id\\d(?!\\d)"); String example = ":p_id1 :p_id10"; Matcher matcher = pattern.matcher(example); while (matcher.find()) System.out.println(matcher.group());
Here's the pattern I made:
This matches strings like:
:p_id1 =:p_id1 :p_id1=
but doesn't match (for instance):