Am doing some semantic analysis on C++ source code.
I have a regular expression to transform the array declarations from
int  
int [number] [number]
int [i * x][ring_size][w + 6]
If you want to match anything inside
, then try using
\\[.+?\\], or something similar. The
? turns the
* into non-greedy. Read more on this page.
Edit: I have to note that, while this works for slightly more complex expression than just numbers, if there are more
 inside the expression, this will not work.
E.g. applying my pattern to
array[anotherarray] results in
[anotherarray, instead of
[anotherarray] (note the extra bracket at the end).
See this answer for more information on bracket matching.