in reply to Recursive capture of a variable number of elements using regexp

Is this the kind of output you're looking for?

perl -ne"print $1,'-',$2||1,' 'while /([A-Z][a-z]*)(\d+)?/g;print qq[\ +n]" CON CH4N2O C-1 H-4 N-2 O-1 C9H12N2O6 C-9 H-12 N-2 O-6 C5H11NO2 C-5 H-11 N-1 O-2 C5H4N4O2 C-5 H-4 N-4 O-2 C10H11N4O9P C-10 H-11 N-4 O-9 P-1 C10H12N4O6 C-10 H-12 N-4 O-6 C5H10O5 C-5 H-10 O-5 C5H12O5 C-5 H-12 O-5 C5H10O5 C-5 H-10 O-5 C27H44O C-27 H-44 O-1 C1694H2993O101 C-1694 H-2993 O-101 ^Z

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re: Recursive capture of a variable number of elements using regexp
  • Download Code