in reply to Re: Wildcard?
in thread Wildcard?

/^R..$/

That will match ray but also ray\n, but not ra\n.

/^R..\z/s
\z is end of string, /s makes . match \n.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
Re: Re: Re: Wildcard?
by Molt (Chaplain) on May 30, 2002 at 12:51 UTC

    If you've got the /s switch on though this'll happily match R\n\n\n, won't it?

    Update: Oops, did wrong number of \n's. R\n\n does seem to pass this match, unless the code below is wrong..

    #!/usr/bin/perl -w use strict; my @tests = ( "R\n\n", # Passes "Roo", # Passes "roo", # Fails "Roo\n", # Fails ); foreach (@tests) { if (/^R..\z$/s) { print "$_ passes\n"; } else { print "$_ fails\n"; } }

      If you've got the /s switch on though this'll happily match R\n\n\n, won't it?

      No, because I also put \z there instead of $. perlre

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.