in reply to Re: simple regex question
in thread simple regex question

This is nothing to do with the original question as such. Just curious. To print 'foo' we can just use this right?  perl -le '$_ = "password=foo&user=bar"; print /password=(.+?)&/;'

output: foo

by the same token, am i correct in assuming if we were setting $1, $2 etc.  /regexstuff/ will return $1 . $2?

thanks

SK

Replies are listed 'Best First'.
Re^3: simple regex question
by tlm (Prior) on Jul 17, 2005 at 02:09 UTC

    am i correct in assuming if we were setting $1, $2 etc. /regexstuff/ will return $1 . $2?

    No, but why guess? Here's the relevant section of perlop:

    m/PATTERN/cgimosx
    /PATTERN/cgimosx

    Searches a string for a pattern match, and in scalar context returns true if it succeeds, false if it fails.

    ...

    If the "/g" option is not used, "m//" in list con­text returns a list consisting of the subexpres­sions matched by the parentheses in the pattern, i.e., ($1, $2, $3...). ... When there are no parentheses in the pattern, the return value is the list "(1)" for success. With or without parentheses, an empty list is returned upon failure.

    the lowliest monk