Home: Perl Programming Help: Regular Expressions:
Matching Everything between two white spaces?



Paragon
New User

Jun 27, 2007, 9:08 AM


Views: 6207
Matching Everything between two white spaces?

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


Views: 6206
Re: [Paragon] Matching Everything between two white spaces?

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


Views: 6197
Re: [KevinR] Matching Everything between two white spaces?

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


Views: 6137
Re: [Paragon] Matching Everything between two white spaces?

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