John

What you're doing looks OK, but it's my guess that either the user name doesn't
start at the beginning of the line or the state doesn't finish at the end, i.e.
you have leading or trailing spaces but have anchored your pattern to the ends
of the string.

Try

    foreach (
            "   root    Wed Aug 22 04:44:59 2001     DLs       ",
            "root    Wed Aug 22 04:44:59 2001     ILs")
    {

        m/ (\w+) \s+ (.+\b) \s+ (\w+) /x;

        print "$1\n";
        print "$2\n";
        print "$3\n";
    }

Which works with or without leading or trailing spaces. It also tidies up the
regex and doesn't hand you a user name padded to 7 characters with spaces (which
yours would, if it worked).

HTH,

Rob


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: 04 September 2001 18:11
> To: [EMAIL PROTECTED]
> Subject: regex: can't match pattern... dang
>
>
> I posted a similar question last week; this is a rephrasing.
>
> I have the following strings:
>
>  root    Wed Aug 22 04:44:59 2001     DLs
>  root    Wed Aug 22 04:44:59 2001     ILs
>  root    Wed Aug 22 04:44:59 2001     DL
>  root    Wed Aug 22 04:44:59 2001     DL
>  root    Wed Aug 22 04:44:59 2001     DL
>  root    Wed Aug 22 04:44:59 2001     DL
>  root    Wed Aug 22 04:46:37 2001     Is
>  root    Wed Aug 22 11:46:38 2001     Ss
>  root    Wed Aug 22 11:46:39 2001     Ss
>  daemon  Wed Aug 22 11:46:40 2001     Is
>  root    Wed Aug 22 11:46:41 2001     Is
>  root    Wed Aug 22 11:46:41 2001     Ss
>  root    Wed Aug 22 11:46:41 2001     Is
>  root    Wed Aug 22 12:31:21 2001     Is
>  postfix Wed Aug 22 12:31:21 2001     I
>  root    Wed Aug 22 12:32:21 2001     Ss
>  nobody  Wed Aug 22 12:32:21 2001     I
>  nobody  Wed Aug 22 12:32:22 2001     I
>  nobody  Wed Aug 22 12:32:22 2001     I
>  nobody  Wed Aug 22 12:32:22 2001     I
>
> I want three things:
>
> user, the entire date, the state.
>
> I'm currently trying to get this with:
>
> for(@procs){
>  /^(.{7})\s+?(.{24})\s+?(\S+?)$/;
>
>
> I want $1 to be the user (e.g. 'root' 'postfix').
> I want $2 to be something like 'Wed Aug 23 05:30:01 2001'.
> I want $3 to be the state, which was a lot of forms, but which is, for
> example 'DLs' above.
>
> Shouldn't this get the first 7, then 24 characters, then the glop that's
> left over?
>
> What am I doing wrong?
>
> -John
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to