Home: Perl Programming Help: Regular Expressions:
Getting part of this string...



danp
Novice

Jun 11, 2002, 10:14 AM


Views: 16046
Getting part of this string...

Hi,
Reading lines in a file I might come across this (this is the whole line):

10.10.10 ETI301S Intermediate file < 1>- Opened.

I want to get the FHI301S section out. Up until 'Intermediate...' part the lengths and format are fixed
e.g. nn.nn.nn<space>ABC123S

Can anyone point me in the right direction. I've tried several things but got nowhere.

TIA
Dan


Jean
User


Jun 12, 2002, 6:12 AM


Views: 16042
Re: [danp] Getting part of this string...

Try this:

Code
  

my $s = q/10.10.10 ETI301S Intermediate file < 1>- Opened./;
$s =~ /\d\d\.\d\d\.\d\d\s+([\w\d]+)\s+/;
print "RESULT: $1\n";



Hope this helps...


Jean Spector
SQA Engineer @ Exanet
jean.spector@softhome.net


There are only 10 types of people in the world -
Those who understand binary, and those who don't.


Paul
Enthusiast

Jul 15, 2002, 5:22 PM


Views: 15997
Re: [Jean] Getting part of this string...

Hi Jean,

>>$s =~ /\d\d\.\d\d\.\d\d\s+([\w\d]+)\s+/; print "RESULT: $1\n";<<

\w actually includes digits so \w\d can be changed to just \w


Jean
User


Jul 15, 2002, 11:26 PM


Views: 15995
Re: [RedRum] Getting part of this string...

Oopsie Blush

I have always thought that \w was equivalent of [A-Za-z_] ...
Thanks for the update :-)


Jean Spector
SQA Engineer @ Exanet
jean.spector@softhome.net


There are only 10 types of people in the world -
Those who understand binary, and those who don't.


Paul
Enthusiast

Jul 16, 2002, 2:46 AM


Views: 15992
Re: [Jean] Getting part of this string...

I believe there is currently no way to only match letters without using the [a-z] character class, as \w includes digits and _ and \d is only digits.


davorg
Thaumaturge / Moderator

Jul 16, 2002, 3:10 AM


Views: 15989
Re: [RedRum] Getting part of this string...


In Reply To
I believe there is currently no way to only match letters without using the [a-z] character class, as \w includes digits and _ and \d is only digits.


There is - [:alpha:]

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Paul
Enthusiast

Jul 16, 2002, 3:32 AM


Views: 15988
Re: [davorg] Getting part of this string...

Its quicker to type [a-z] Angelic but thanks for setting me straight.


davorg
Thaumaturge / Moderator

Jul 16, 2002, 3:46 AM


Views: 15986
Re: [RedRum] Getting part of this string...

Ah, but [a-z] doesn't deal with locales and unicode - this may or may not be important to you :)

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks