in reply to Regular Expression to find Word Prefixes

Well, if the prefixes never contain spaces, Zaxo's fix works perfectly.

Though, if you cannot make that assumption, but you can make the assumption that the actual chemical names never have a space in them, you can use japhy's sexeger techiniques. That is, reverse the string and apply the regex there.

#!/usr/bin/perl -w use strict; my @data = ('12 chem1', '1/2 chem2', '(N+1) chem3', '2M chem4', 'N chem5'); my $chem; foreach (@data) { $chem = reverse $_; $chem =~ s/^\S+//; $chem = reverse $chem; print $chem . "\n"; }
Jeremy

Replies are listed 'Best First'.
Re: Re: Regular Expression to find Word Prefixes
by Juerd (Abbot) on May 19, 2002 at 19:01 UTC

    $chem = reverse $_; $chem =~ s/^\S+//; $chem = reverse $chem; print $chem . "\n";

    How about

    ($chem) = $chem =~ /(.*)\s/

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

Re: Re: Regular Expression to find Word Prefixes
by arunhorne (Pilgrim) on May 19, 2002 at 21:39 UTC
    I really like the that reverse idea, and thanks for pointing out japhy's book thats really handy too., Arun