X
X. Lee
Hello, I am in need of some regex assistance..
In my project, I need to parse a String and replace everything within
brackets with the String "xx".
I thought this would be pretty simple, using the Pattern "(\[.+\])".
this pattern works fine if there is only one set of brackets in my
String, however it fails if I have multiple bracket sets because it
only seems to consider the very first and very last brackets found.
e.g.:
"This is my [test] String" becomes "This is my [xx] String" <-- fine
but "This is [my] other [test] String" also becomes "This is my [xx]
String" instead of "This is [xx] other [xx] String" <-- not fine
So the matcher finds "[my] other [test]" instead of finding [my] and
[test] separately.
How can I make it find each set of brackets separately?
In my project, I need to parse a String and replace everything within
brackets with the String "xx".
I thought this would be pretty simple, using the Pattern "(\[.+\])".
this pattern works fine if there is only one set of brackets in my
String, however it fails if I have multiple bracket sets because it
only seems to consider the very first and very last brackets found.
e.g.:
"This is my [test] String" becomes "This is my [xx] String" <-- fine
but "This is [my] other [test] String" also becomes "This is my [xx]
String" instead of "This is [xx] other [xx] String" <-- not fine
So the matcher finds "[my] other [test]" instead of finding [my] and
[test] separately.
How can I make it find each set of brackets separately?