in reply to Regular Expression to find Word Prefixes


Just use split:

my $var = '(N+1) chem3'; # Or whatever

my ($var1, $var2) = split (/\s/,$var);

print "$var1\n";
print "$var2\n";
  • Comment on Re: Regular Expression to find Word Prefixes

Replies are listed 'Best First'.
Re: Re: Regular Expression to find Word Prefixes
by arunhorne (Pilgrim) on May 20, 2002 at 14:37 UTC

    xgunnerx ... this isn't an option because of the following real life situation:

    Two atomic entries found in my data set:

    N'-phosphoguanidinoethyl methyl phosphate 2N N'-phosphoguanidinoethyl methyl phosphate

    For the first entry your script will return the following when it should return an empty string as there is no prefix:

    N'-phosphoguanidinoethyl methyl

    For the second entry it will return the following when it should return "2N" as it is the prefix (note that the entire name minus prefix is not returned by your code as the 'methyl phosphate' biut is missing:

    2N N'-phosphoguanidinoethyl

    I admit that given the original data set that I provided your solution would work, but it does not allow for arbitrary names with spaces.

    Arun