1827882 Members
1110 Online
109969 Solutions
New Discussion

Perl Regular Expressions

 
SOLVED
Go to solution
Junior C.
Frequent Advisor

Perl Regular Expressions

I have the following in a text file.

autocalcs
cdms
mservrs
XIPMessageQueue_7.0

=====

while($line = )
{
chomp ($line);
$line =~ /^(\w+)\s+(\S+)........

output from above:

autocalcs
cdms
mservrs

===============

while($line = )
{
chomp ($line);
$line =~ /^(\w+[_0-9.]+)\s+(\S+)........

output:

XIPMessageQueue_7.0


I'm looking for syntax to match all 4
autocalcs
cdms
mservrs
XIPMessageQueue_7.0


I appreciate all help.


JC.




3 REPLIES 3
Stuart Browne
Honored Contributor
Solution

Re: Perl Regular Expressions

Well, you could just use \S+ (non-space), but that'll allow you to include symbols as well.

\w already does alpha-numeric-and-underscore, what you need to include is the '.'.

So '/^([\w\.]+)\s+(\S+)...' is what you're after.
One long-haired git at your service...
Alexander Chuzhoy
Honored Contributor

Re: Perl Regular Expressions

This will also work:

$line=~/^([A-z0-9_.]+)\s+(\S+)....

Regards.
Junior C.
Frequent Advisor

Re: Perl Regular Expressions

Thread Close