CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



danp
Novice

Jun 11, 2002, 10:14 AM

Post #1 of 8 (6187 views)
Getting part of this string... Can't Post

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

Post #2 of 8 (6183 views)
Re: [danp] Getting part of this string... [In reply to] Can't Post

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

Post #3 of 8 (6138 views)
Re: [Jean] Getting part of this string... [In reply to] Can't Post

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

Post #4 of 8 (6136 views)
Re: [RedRum] Getting part of this string... [In reply to] Can't Post

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

Post #5 of 8 (6133 views)
Re: [Jean] Getting part of this string... [In reply to] Can't Post

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

Post #6 of 8 (6130 views)
Re: [RedRum] Getting part of this string... [In reply to] Can't Post


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

Post #7 of 8 (6129 views)
Re: [davorg] Getting part of this string... [In reply to] Can't Post

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


davorg
Thaumaturge / Moderator

Jul 16, 2002, 3:46 AM

Post #8 of 8 (6127 views)
Re: [RedRum] Getting part of this string... [In reply to] Can't Post

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

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives