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:
Matching Everything between two white spaces?

 



Paragon
New User

Jun 27, 2007, 9:08 AM

Post #1 of 4 (2676 views)
Matching Everything between two white spaces? Can't Post

Hello All



This is my first post here and it regards matching everything that lies between two white spaces that that has test to the right of it and left of it that is not required the match i wish to make consists of \w+\d+\w+ sometimes has a hyphon (-) but not always.

I have tried using \s+(\w+)\s+ but this does not match -

Any sugestions would be helpfull

Thanks

SRG


KevinR
Veteran


Jun 27, 2007, 9:37 AM

Post #2 of 4 (2675 views)
Re: [Paragon] Matching Everything between two white spaces? [In reply to] Can't Post

THE explanation of what you are doing is hard to understand. The part I do understand is that if you need a hyphen in the pattern you can do this:

\s+([\w-]+)\s+

but that is a very general match and will match if there is only a hyphen and no word characters, and the hyphen can be anywhere in the pattern. Post some examples of what you are trying to match.
-------------------------------------------------


Paragon
New User

Jul 2, 2007, 3:15 AM

Post #3 of 4 (2666 views)
Re: [KevinR] Matching Everything between two white spaces? [In reply to] Can't Post

Hello Thank you for your reply.

Here are some examples as requested:

101546 Backup Queued ateunix weekly-full trasdps034 atedb01 7075

101532 Backup Done 0 atewin weekly-full trastpw006v atedb01 2499

101207 Backup Done 196 atewin - trastaw003-mgt atedb01 166255

101532 Backup Done 0 atewin inc-bak trast-pw022v atedb01 2499


The bold names are the ones I wish to extract. I know I could use a split on space here but for completeness I would like to know what regex if any would fullfill the match for all of the above.



Kind Regards

SRG


Mathi
New User

Aug 28, 2007, 5:44 AM

Post #4 of 4 (2606 views)
Re: [Paragon] Matching Everything between two white spaces? [In reply to] Can't Post

the following will give help you,

$a='101546 Backup Queued ateunix weekly-full trasdps034 atedb01 7075';

if( $a =~ m/(\s+tras[\w|\d|-]+\s+)/)

{
print " $&" ;

};



Regds,

Mathi

 
 


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

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