Reputation: 115
String xpath = "A/B/C[Hello world]/D";
In the above string I have to replace the square brackets and the content between it.
Final output should be: A/B/C/D
.
I have written the below code but it does not work if there is a a space between Hello
and World
:
String Xpath1 = xpath.replaceAll("\\[[\\S]+\\]", "");
Upvotes: 0
Views: 449
Reputation: 2188
This should do the trick:
String xpathResult = xpath.replaceAll("\\[.*\\]", "");
Upvotes: 0
Reputation: 887479
Your regex matches all non-whitespace characters. Therefore, it will not match a space.
It sounds like you actually want to match all characters except ]
:
[^\\]]
Upvotes: 2