in reply to Regexps for Parsing Brackets in Chemical Formulae
In the first line we are replacing any parens and their contents (which may not include parens) if followed by a non number with just the contents $1 and the non number $2. The |$ is to get a paren as the last character of a line.1 while $formula =~ s/\(([^()]+)\)(\D|$)/$1$2/g; 1 while $formula =~ s/\(([^()]+)\)(\d)/$1x$2/e;
In line 2 we find parens followed by a number and multiply them out.
-monkfish (The Fishy Monk)
|
|---|