Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: How to avoid an alphabet and integer next to it in a string?

by piscean (Acolyte)
on Mar 21, 2014 at 18:05 UTC ( #1079316=note: print w/ replies, xml ) Need Help??


in reply to Re: How to avoid an alphabet and integer next to it in a string?
in thread How to avoid an alphabet and integer next to it in a string?

Oops! This is giving me wrong output too. Hope the code I posted below gives an idea of what I wanted.


Comment on Re^2: How to avoid an alphabet and integer next to it in a string?
Re^3: How to avoid an alphabet and integer next to it in a string?
by hazylife (Monk) on Mar 21, 2014 at 18:08 UTC
    What about this?
    $formula =~ s/H\d*//g;
      Nope :( If the molecular formula entered is C6H9, the code should give an output equal to 12.01*6=72.06. After applying this, it's giving me 12.01*69=828.69

      The Problem with s/H\d*//g is that it will also remove the H from HgS (ok,, not organic chemistry, but you get the point).

      One way to avoid that is to use a negative look-ahead:

      s/H(?![a-z])\d*//</c> <p>Or if you prefer the Unicode-y approach:</p> <code>s/H(?!\p{Ll})\d*//
        will also remove the H from HgS
        Yes, you're right, I stand corrected.
        The first code says Forbidden chars again. Second one, Unicode -y approach? I am not familiar with that. Could you help me? How should the input be in an unicode -y approach?

        Or simpler, H\d+. \d* will match *zero* or more digits, \d+ matches *one* or more.

        update: oh, wait, ignore me. You need to knock out the H in (eg) NaOH, which doesn't have a digit after it.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-10-24 07:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (130 votes), past polls