Question

I have a string that contains multiple occurrences of text enclosed in square brackets that I need to remove such as:

10/21/2012 12:12:15 [12:12:28] Admitted Last,First (Card #555) at Lobby Turnstile # 4 (IN) [In] [Noticed]

I tried String.replaceAll, replaceFirst using the regex "\[.*\]" which removes all the texts between the first [ and last ] and I end up with

10/21/2012 12:12:15

I'm stuck on how to specify the expression. Any help would be appreciated.

Was it helpful?

Solution

use a non-greedy quantifier: "\[.*?\]"

or specifically exclude the close char: "\[[^]]*\]"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top