Regular Expressions 101

Community Patterns

Elements from matrix

1

Regular Expression
PCRE (PHP <7.3)

/
(\[[^\]]+\]),?
/
g

Description

If you have "[[2,3],[4,5]]" representing a matrix, you can't just Split(',') because that'll give you "[[2" "3]" "[4" "5]]". Removing the first '[' and last ']' and using this regex will give you the elements "[2,3]" "[4,5]".

Cheers

Submitted by M.G. - 8 years ago