Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by AnomalousMonk (Archbishop)
on Mar 21, 2014 at 20:09 UTC ( [id://1079349]=note: print w/replies, xml ) Need Help??


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

Maybe something like:

c:\@Work\Perl\monks>perl -wMstrict -le "my $Hn = qr{ H (?! [[:lower:]]) \d* }xms; my $not_Hn = qr{ (?! $Hn) }xms; ;; use constant FORMULA => 'HC6H5OHHg2HeBr3H'; ;; my $s = FORMULA; print qq{'$s'}; $s =~ s{ $Hn }''xmsg; print qq{'$s'}; ;; $s = FORMULA; my @elements = $s =~ m{ $not_Hn [[:upper:]] [[:lower:]]? \d* }xmsg; printf qq{'$_' } for @elements; " 'HC6H5OHHg2HeBr3H' 'C6OHg2HeBr3' 'C6' 'O' 'Hg2' 'He' 'Br3'

Replies are listed 'Best First'.
Re^2: How to avoid an alphabet and integer next to it in a string?
by piscean (Acolyte) on Mar 21, 2014 at 20:43 UTC
    Thanks! This helped too :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-20 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found