AndyM
AndyM

Reputation: 622

Perl match ALL multiple words in string

I've string from a system such as: "Mar 4 11:56:54 nxecopapp ftpd[20773]: [ID 44443 auth.error] unable to open module: stat (/usr/lib/security/pam_unix_session.so.1) failed: No such file or directory"

I need a perl regex that matches on ftpd and auth.error and pam_unix_session.so.1 , ie all three

Upvotes: 1

Views: 1209

Answers (4)

toolic
toolic

Reputation: 62037

use warnings;
use strict;

my $s = 'Mar 4 11:56:54 nxecopapp ftpd[20773]: [ID 44443 auth.error] unable to open module: stat (/usr/lib/security/pam_unix_session.so.1) failed: No such file or directory';

if ($s =~ /ftpd .* auth\.error .* pam_unix_session\.so\.1/x) {
    print "match\n";
}

See: perlre

Upvotes: 1

stema
stema

Reputation: 92976

(?=.*ftpd)(?=.*auth\.error)(?=.*pam_unix_session\.so\.1).*$

You can verify this online on rubular

Upvotes: 1

markijbema
markijbema

Reputation: 4055

Try this:

m/ftpd|auth\.error|pam_unix_sessions\.so\.1/

Edit:

Sorry, I read to hastily, above will match or, instead, you need this to match them all:

m/(?=.*ftpd)(?=.*auth\.error)(?=.*pam_unix_session\.so\.1).*/

Upvotes: 2

Grrrr
Grrrr

Reputation: 2536

Since the order seems to be fixed, you need to compose a match like this: match ftpd first, then any number of chars, possibly zero, then auth.error, then any number of chars, possibly zero, then pam_unix_session.so.1.

This directly converts into a regular expression. The conversion procedure is left as an exercise to the reader. :-)

Upvotes: 3

Related Questions