Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Re: Re: Regexps for Parsing Brackets in Chemical Formulae

by Elgon (Curate)
on Nov 05, 2001 at 09:26 UTC ( #123283=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Regexps for Parsing Brackets in Chemical Formulae
in thread Regexps for Parsing Brackets in Chemical Formulae

Stefp,

Muchas gracias - one minor alteration to take account of the fact that certain artificial elements have, under certain nomenclatures, three letters rather than one or two...

s/([A-Z](?:[a-z]{0,2})?)(\d*)/  $count{$1} += $2 ? $2  : 1 ;''/eg;

Otherwise, perfect!

Ta, Elgon.

"Without evil there can be no good, so it must be good to be evil sometimes.
--Satan, South Park: Bigger, Longer, Uncut.


Comment on Re: Re: Re: Re: Regexps for Parsing Brackets in Chemical Formulae
Download Code
Re: Re: Re: Re: Re: Regexps for Parsing Brackets in Chemical Formulae
by stefp (Vicar) on Nov 07, 2001 at 22:27 UTC
    Not quite perfect:

       s/([A-Z][a-z]{0,2})(\d*)/ $count{$1} += $2 ? $2 : 1 '' /eg;

    is cleaner. The (?:) was a unneeded left-off in my code and when you added the {0,2} modifier, the ? modifier became redundant. Or {2}? could be used instead of {0,2}.

    Strangely for the golfers {,2} is not supported; it should be expected to be supported because {2,} is.

    -- stefp

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://123283]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-09-20 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (157 votes), past polls