[Regexp] What regular expression to use

Dimitri Pissarenko <[email protected]>
Newsgroups gmane.comp.gnu.regexp
Message-ID <[email protected]>
Hello!

I have the following text:

<textfragment>
[{{a, b, c}, 
{d, e, f}}]

[a+b]

a[i]

sum(a[i],i,n1,n2)

root[i](a0, ..., an)
</textfragment>

From this text, I want to find all text blocks enclosed by brackets ([
and ]).

Sometimes, these brackets have other meaning (like a[i] and root[i]).

Therefore, I want to create a regular expression, which 

1) finds all text blocks enclosed by brackets, provided
2) that the character before the "opening" bracket [ isn't an
alphanumeric character.

In other words, that regular expression should find two text blocks in
the above example, namely

a) [{{a, b, c}, 
{d, e, f}}]

b) [a+b]

I've tried following regular expressions, but neither of them produced
exactly that result:

<code>
//regularExpression=new RE("[\\n\\r\\s]\\[(.*)\\]",
RE.REG_DOT_NEWLINE);
//regularExpression=new RE("[^a-zA-Z]\\\[.*\\]", RE.REG_DOT_NEWLINE);

regularExpression=new RE("\\n\\[(.*)\\]", RE.REG_DOT_NEWLINE);
				
matches=regularExpression.getAllMatches(area.getText());
for (int i=0;i < matches.length ; i++ )
{
	System.out.println("-----");
	System.out.println(matches[i].toString(0));
}
</code>

This piece of code should print following text:

a) {{a, b, c}, 
{d, e, f}}

b) a+b

What am I doing wrong?

TIA

dap
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.