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'
In reply to Re: How to avoid an alphabet and integer next to it in a string?
by AnomalousMonk
in thread How to avoid an alphabet and integer next to it in a string?
by piscean
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |