[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Regexp] What regular expression to use
From: |
Dimitri Pissarenko |
Subject: |
[Regexp] What regular expression to use |
Date: |
Tue, 29 Jun 2004 12:42:30 +0200 |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Regexp] What regular expression to use,
Dimitri Pissarenko <=