문제

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.

도움이 되었습니까?

해결책

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top