Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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


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.

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://123283]
[choroba]: LanX I miss working in a bank sometimes...
[Corion]: Discipulus: Ooof. Especially yearly things are things I like to automate instead of trying to remember how I did things last year...
[Corion]: And the second rule that I've learned is, that there is no one-off job, so writing a program for it pays off almost immediately. The third rule is to give all my programs numbers and have them reproduce that number in the name of their output files. :)
[Discipulus]: the true part is that also specification change between years.. but well our job is cheap but dont abuse of us.. ;=)
[LanX]: Choroba: do you miss chaos with ties? apply at the US government.. ;)
[ambrus]: Corion: those are good rules.
[ambrus]: Discipulus: oh sure. the input data has different filenames every time I get them.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2017-03-29 12:12 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (350 votes). Check out past polls.