Professional Web Applications Themes

Newbie Regex Help - PERL Miscellaneous

Hello, I am trying to use Regex for some of my scripts. My requirements is as follows, I am trying to process the output of a command from Rational Clearcase. The output I get is something like this /main/1a_br_1/tmp_fix_2.2.0/14 From this, I would like to get the number after the last "/", i.e 14. It is fixed, that after the last "/", there will be digits. Any ideas, how I could achieve this by using regex. Thanks, Jayanth ~~~~~...

  1. #1

    Default Newbie Regex Help

    Hello,
    I am trying to use Regex for some of my scripts. My requirements is as
    follows,

    I am trying to process the output of a command from Rational Clearcase. The
    output I get is something like this
    /main/1a_br_1/tmp_fix_2.2.0/14

    From this, I would like to get the number after the last "/", i.e 14. It is
    fixed, that after the last "/", there will be digits. Any ideas, how I could
    achieve this by using regex.

    Thanks,
    Jayanth
    ~~~~~




    Jayanth Guest

  2. #2

    Default Re: Newbie Regex Help

    "Jayanth S Vasisht" <bosch.com> wrote in
    news:bn7pah$2b6$fe.internet.bosch.com:
     


    Two methods come to mind (both assume your input is in $_):


    my $thingy = $1 if m#.*/(.*)#;


    or


    my $thingy = (split /\//)[-1];



    Cheers,
    Bernard
    Bernard Guest

  3. #3

    Default Re: Newbie Regex Help

    Jayanth S Vasisht wrote: 

    ($number) = $output =~ /.+\/(\d+)/;

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl

    Gunnar Guest

  4. #4

    Default Re: Newbie Regex Help

    "Jayanth S Vasisht" <bosch.com> wrote in
    news:bn7pah$2b6$fe.internet.bosch.com:
     


    Two methods come to mind (both assume your data is in $_):


    my ($thingy) = m#.*/(.*)#;


    or


    my $thingy = (split /\//)[-1];



    Cheers,
    Bernard
    Bernard Guest

  5. #5

    Default Re: Newbie Regex Help

    On Thu, 23 Oct 2003 11:04:59 +0530, "Jayanth S Vasisht"
    <bosch.com> wrote:
     

    if ( /(\d+)$/{
    print "Found $1\n";
    }else{
    # something wrong
    }


    Phil
    --
    Ignore coming events if you wish to send me e-mail
    Philip Guest

  6. #6

    Default Re: Newbie Regex Help

    Jayanth S Vasisht <bosch.com> wrote: 
     
     
     



    #!/usr/bin/perl

    use strict;
    use warnings;

    my $test_string = '/main/1a_br_1/tmp_fix_2.2.0/14';

    # [\d] means 'a digit'
    # [\d]+ means 1 or more digits
    # ([\d]+) means remember the actual string that triggered a match here
    # and save it to $1 ---- since this is first occurence of parenthises
    # in regex. next parenthisized thing, if it exists will go in $2.
    # $1,$2 ... etc may get side effected by all kinds of stuff, so grab
    # these right away for dependable results
    # $, at the end of a regeex, means 'end of string'
    # \/ means /

    $test_string =~ m/\/([\d]+)$/ || die;

    my $last_hunk_o_digits = $1;

    print "$last_hunk_o_digits\n";

    --
    I used to think government was a necessary evil.
    I'm not so sure about the necessary part anymore.
    chance@austin.rr.com Guest

  7. #7

    Default Re: Newbie Regex Help

    Jayanth S Vasisht wrote:

    (snipped)
     
     
     

    Your "something like this" is grossly unacceptable. It is quite
    rude of you to provide phoney data. When I read fabricated phoney
    data, I am tempted to provide fabricated phoney code examples.
    However, I am not that rude, unless sufficiently annoyed.

     


    $input = "/main/1a_br_1/tmp_fix_2.2.0/14";

    print substr ($input, rindex ($input, "/") + 1);


    Purl Gurl
    --
    Learn My Native Tongue, Choctaw!
    http://www.purlgurl.net/~choctaw/
    Purl Guest

  8. #8

    Default Re: Newbie Regex Help


    "Purl Gurl" <net> wrote in message
    news:net... 
    > [/ref]
    The 

    >
    > Your "something like this" is grossly unacceptable. It is quite
    > rude of you to provide phoney data. When I read fabricated phoney
    > data, I am tempted to provide fabricated phoney code examples.
    > However, I am not that rude, unless sufficiently annoyed.
    >[/ref]
    <further snipped>

    My Many thanks to all those who answered. It was very helpful :-).

    To Purl Gurl: I do not know what makes you think that I have provided
    "phoney data". The output what I have mentioned, is very common when using
    Rational Clearcase commands, which is called as the Version Information. I
    just provided it as an example. FYI...Rational Clearcase is a "Configuration
    Management and Version Control Tool".
    Anyway, thanks for your help too.

    --JSV


    JSV Guest

  9. #9

    Default Re: Newbie Regex Help

    "JSV" <bosch.com> wrote in
    news:bn7tb6$5rh$fe.internet.bosch.com:
     [/ref]


    [...]

     
    ^^^^^^^^ 


    "Rational" and "Purl Gurl" should never appear in the same paragraph. Bah,
    in the same book. Do yourself a favour and killfile her now. She is too
    ridiculous to waste your time on.


    Cheers,
    Bernard
    Bernard Guest

  10. #10

    Default Re: Newbie Regex Help

    JSV wrote:
     [/ref]

    (snipped)
     [/ref][/ref]
     


    Nothing "makes" me think this. It is not possible for you nor
    others to "make" me think as you wish. I certainly have a mind
    of my own and think as I please.

    You clearly state your data is fabricated, this is, phoney data.

    You state this. I accept your statement on its face value.

    The nature of data almost always determines the nature of a program.
    Data is the most critical factor considered when writing a program.

    You provide phoney data which, in turn, discounts most possibilities
    of alternative choices in programming. There are many ways to approach
    programming tasks, especially with Perl. Phoney data precludes any
    factual ysis which precludes both logical and factual coding.

    Programming is an exacting art which does not allow for your
    "something like this" data, unless you are working at writing
    pseudo artificial intelligence programs which make educated
    guesses at what data means.

    Microsoft Internet Explorer comes to mind as a program which
    attempts to guess at "something like this" data.

    I use only modified Mozilla browsers for that very reason.

    My suggestion is do not fabricate data and I will not
    tersely comment on how annoying is doing just such.

    I find it annoying for you to fault another for your mistakes.


    Purl Gurl
    --
    Corvette Mako Sharks! 56 Chevy Napco 4X4!
    http://www.purlgurl.net/~godzilla/
    Purl Guest

  11. #11

    Default Re: Newbie Regex Help

    [This followup was posted to comp.lang.perl.misc]

    In article <bn7pah$2b6$fe.internet.bosch.com>,
    bosch.com says... 

    $data = "/main/1a_br_1/tmp_fix_2.2.0/14";
    parts = split(/\//,$data);
    $digits = pop parts;
    Master Guest

  12. #12

    Default Re: Newbie Regex Help

    Bernard El-Hagin wrote: 

    Case proven - just look at her next reply.

    She's some sort of schizo, and I think she thinks it's really funny to play
    tedious annoying word games to the Nth degree. Maybe she could be funny in
    person, but her efforts never translate to the cold heartless medium of the
    written word on the internet.

    Generally, she just es off a lot of people, and that, a lot.


    Andrew Guest

  13. #13

    Default Re: Newbie Regex Help

    Andrew Hamm wrote: 

    Actually, this newsgroup is a wasteland anyway, unfortunately.

    As I scan the list for the first time in 6 months, I see that the bickering,
    anger, abuse and general stupidity continues unabated. I don't know what I
    was thinking, re-subscribing here...


    Andrew Guest

  14. #14

    Default Re: Newbie Regex Help

    Andrew Hamm wrote: 

    What a luck, then, that people like yourself stand out from the rest
    with constructive, on-topic contributions.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl

    Gunnar Guest

Similar Threads

  1. regex
    By chris in forum PHP Development
    Replies: 12
    Last Post: January 6th, 01:48 PM
  2. regex bug?
    By Zach in forum Ruby
    Replies: 4
    Last Post: January 31st, 09:53 PM
  3. [newbie] regex question
    By Luc in forum PHP Development
    Replies: 5
    Last Post: December 30th, 08:43 AM
  4. I know I can do this with a regex, but...
    By Tman in forum PERL Miscellaneous
    Replies: 4
    Last Post: September 21st, 06:54 PM
  5. \s in regex
    By s moon in forum Ruby
    Replies: 5
    Last Post: June 27th, 06:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139