parsing a string

Discussion in 'Perl Misc' started by marie, Nov 20, 2006.

  1. marie

    marie Guest

    I have a string for example "perl878juio"

    I want to cut off everthing beginning with the first number, so I would
    be left with "perl"

    Is there a simply way to do this?
     
    marie, Nov 20, 2006
    #1
    1. Advertising

  2. marie

    Paul Lalli Guest

    marie wrote:
    > I have a string for example "perl878juio"
    >
    > I want to cut off everthing beginning with the first number, so I would
    > be left with "perl"
    >
    > Is there a simply way to do this?


    Yes.

    Use a regular expression and the s/// operator. Search for a digit
    followed by "anything", and replace with nothing.

    Read `perldoc perlretut` to get you started with doing this. Once you
    make your attempt, feel free to post a short-but-complete script here
    if it does not work to your satisfaction.

    Paul Lalli
     
    Paul Lalli, Nov 20, 2006
    #2
    1. Advertising

  3. marie wrote:
    > I have a string for example "perl878juio"
    >
    > I want to cut off everthing beginning with the first number, so I would
    > be left with "perl"
    >
    > Is there a simply way to do this?


    $ perl -le'$_ = q[perl878juio]; print; s/\d.*//; print'
    perl878juio
    perl



    John
    --
    Perl isn't a toolbox, but a small machine shop where you can special-order
    certain sorts of tools at low cost and in short order. -- Larry Wall
     
    John W. Krahn, Nov 20, 2006
    #3
  4. marie <> wrote:
    > I have a string for example "perl878juio"
    >
    > I want to cut off everthing beginning with the first number, so I would
    > be left with "perl"
    >
    > Is there a simply way to do this?



    Yes.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Nov 21, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    932
    GIMME
    Feb 11, 2004
  2. Naren
    Replies:
    0
    Views:
    612
    Naren
    May 11, 2004
  3. Christopher Diggins
    Replies:
    0
    Views:
    627
    Christopher Diggins
    Jul 9, 2007
  4. Christopher Diggins
    Replies:
    0
    Views:
    456
    Christopher Diggins
    Jul 9, 2007
  5. John Levine
    Replies:
    0
    Views:
    763
    John Levine
    Feb 2, 2012
Loading...

Share This Page