Newbie Regex Help

J

Jayanth S Vasisht

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
~~~~~
 
G

Gunnar Hjalmarsson

Jayanth said:
/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+)/;
 
P

Philip Lees

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
 
C

chance

Jayanth S Vasisht said:
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";
 
J

JSV

Purl Gurl said:
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.
<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
 
M

Master Web Surfer

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

/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;
 
A

Andrew Hamm

Bernard said:
"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.
 
A

Andrew Hamm

Andrew said:
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...
 
G

Gunnar Hjalmarsson

Andrew said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top