Regex to return the characters between square brackets (but not the brackets)

munyul

I'm looking for a RegEx to return all the characters between two square brackets, and only the characters, not the brackets themselves.

For example given a string that looks like "[A][B2][1,1][ABC]"

The RegEx should return: A, B2, 1,1, ABC

I have tried various expressions for both String#split and Pattern & Match.

The closest I've gotten was:

String.split("[\\[]*[\\]]"); and Pattern.compile("\\[[^\\]]+(?=])");

Both of these return: [A, [B2, [1,1, [ABC

I've found other expressions that return the values with the enclosing brackets (ie. Pattern.compile("\\[[^\\]]*\\]");) but that is not what I'm after.

Does someone know the correct expression? or is what I'm trying to do not possible?

vks
(?<=\\[).*?(?=\\])

You need lookaheads and lookbehinds.or

(?<=\\[)[^\\]]*(?=\\])

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Regex to return the characters between square brackets (but not the brackets)

From Dev

Javascript/regex: Remove text between square brackets

From Dev

Regex to find all quotes between square brackets

From Dev

Regex Matching Square Brackets

From Dev

Regex Matching Square Brackets

From Dev

Square brackets breaking regex?

From Dev

Splitting by " | " not between square brackets

From Dev

Regex split with comma but not in Square Brackets and not in Brackets

From Dev

Regex getting two specific characters within square brackets

From Dev

Capture between round brackets and square brackets

From Java

Regex to find period in square brackets

From Dev

python regex not detecting square brackets

From Dev

Regex for matching square brackets and number

From Dev

Regex Remove Square Brackets/Whitespace

From Dev

Python Regex behaviour with Square Brackets []

From Dev

regex match square brackets once

From Dev

php regex square brackets and commas

From Dev

Regex to extract from square brackets?

From Dev

Regex in square brackets not preceeded or followed by

From Dev

how to build a regex with square brackets

From Dev

javascript regex skip square brackets

From Dev

regex remove everything not in square brackets

From Dev

remove text between square brackets

From Dev

spacing between square brackets of an array

From Dev

To delete everything between square brackets

From Dev

remove text between square brackets

From Dev

Regex Between Brackets

From Dev

php regex - get content with square brackets escaped inside square brackets

From Dev

PHP Regex replace text between brackets AND brackets