Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Regular Expression to find Word Prefixes

by xgunnerx (Initiate)
on May 20, 2002 at 13:23 UTC ( #167828=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2022-07-03 02:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (103 votes). Check out past polls.

    Notices?