Regular Expressions help

Joel Pearson pearj at
Mon Dec 9 21:42:31 EST 2002



I'm having trouble with regular expressions.

I have a regular expression "/value=(.{3})> \(+([^)]+)\)+/" that usually
does what I want it to.

But in some cases it screws over.  This is how its supposed to work:

Just say I have this data "<option value=IMD> (IMDEX LIMITED) IMD",
normally what happen is it pulls out IMB and IMDEX LIMITED.


But sometimes company names manage to get brackets into their names,
which really throws a spanner in the works, eg:

"<option value=IMF> (IMF (AUSTRALIA) LTD) IMF"

The first bit works, it gets IMF, but then it screws up and only gets
the first half of the company name "IMF (AUSTRALIA".


Is there any way to make the regular expression a litter smarter? I was
thinking maybe if the expression somehow 'knew' that if it got 2 open
brackets in the company name, that it must have 2 closing brackets as
well.  Or maybe the fact that it ends in the first value as well, ie it
goes IMF company name IMF, can regular expressions store variables?


Anyway as you can see I really have no idea when it comes to regular
expressions, can anyone help me out?







Joel Pearson

Email: pearj at

ICQ:1580379 <,,,00.html?Uin=1580379> 

MSN: joelpearson at


-------------- next part --------------
HTML attachment scrubbed and removed

More information about the linux mailing list