Newbie Regex Help

Discussion in 'Perl Misc' started by Jayanth S Vasisht, Oct 23, 2003.

  1. 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 S Vasisht, Oct 23, 2003
    #1
    1. Advertising

  2. Jayanth S Vasisht wrote:
    >
    > /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.


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

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Oct 23, 2003
    #2
    1. Advertising

  3. Jayanth S Vasisht

    Philip Lees Guest

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

    >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.


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


    Phil
    --
    Ignore coming events if you wish to send me e-mail
     
    Philip Lees, Oct 23, 2003
    #3
  4. Jayanth S Vasisht

    Guest

    Jayanth S Vasisht <> wrote:
    > 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
    > ~~~~~




    #!/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.
     
    , Oct 23, 2003
    #4
  5. Jayanth S Vasisht

    JSV Guest

    "Purl Gurl" <> wrote in message
    news:...
    > Jayanth S Vasisht wrote:
    >
    > (snipped)
    >
    > > 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

    >
    > 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.
    >

    <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, Oct 23, 2003
    #5
  6. [This followup was posted to comp.lang.perl.misc]

    In article <bn7pah$2b6$>,
    says...
    > /main/1a_br_1/tmp_fix_2.2.0/14
    >


    $data = "/main/1a_br_1/tmp_fix_2.2.0/14";
    @parts = split(/\//,$data);
    $digits = pop @parts;
     
    Master Web Surfer, Oct 23, 2003
    #6
  7. Jayanth S Vasisht

    Andrew Hamm Guest

    Bernard El-Hagin wrote:
    >
    > "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.


    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 pisses off a lot of people, and that, a lot.
     
    Andrew Hamm, Oct 24, 2003
    #7
  8. Jayanth S Vasisht

    Andrew Hamm Guest

    Andrew Hamm wrote:
    >
    > 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 pisses off a lot of people, and that, a lot.


    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 Hamm, Oct 24, 2003
    #8
  9. 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...


    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 Hjalmarsson, Oct 24, 2003
    #9
    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. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    712
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Rick Venter

    perl regex to java regex

    Rick Venter, Oct 29, 2003, in forum: Java
    Replies:
    5
    Views:
    1,634
    Ant...
    Nov 6, 2003
  3. Replies:
    2
    Views:
    600
  4. Xah Lee
    Replies:
    1
    Views:
    943
    Ilias Lazaridis
    Sep 22, 2006
  5. Replies:
    3
    Views:
    769
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page