Sample Header Ad - 728x90

Is possible to discard outer brackets in regex and consider inner bracket inside?

0 votes
1 answer
276 views
I have many patterns with bracket enclosure, I made a regular expression where is not considering brackets and just only what is inside/between them, but exists a problem when the text within brackets contain [] brackets too. Thanks! Regex: (?(?<=\[).*?\[?(?=\])) For example,
A)   [ClusterReceiver            ]
B)   [first-second-third-8050-exec-a       ]
From above, B) is working perfectly, but A) not What is being returned for every case (without quotes): ---
B) "first-second-third-8050-exec-a "
A) "ClusterReceiver[99"
What is desired? ------------------
B) "first-second-third-8050-exec-a "
A) "ClusterReceiver"
The problem is when exist [ ] bracket enclosure within outer [ ] enclosure. The worst case is when exists that problem like A), can you help me by giving a suggestion how to accept at least 1 bracket, in order to have A) as desired "ClusterReceiver" ?
Asked by dcubaz (23 rep)
Nov 16, 2022, 08:14 PM
Last activity: Nov 16, 2022, 08:27 PM