Great stuff. Regexp objects rock. It worked perfectly and helped with some other things too. Thanks a lot Jeff. CC
>From: Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> >Reply-To: [EMAIL PROTECTED] >To: claement claementson <[EMAIL PROTECTED]> >CC: [EMAIL PROTECTED] >Subject: Re: very basic regexp question >Date: Wed, 26 Sep 2001 22:54:33 -0400 (EDT) > >On Sep 27, claement claementson said: > > >1. I'm trying to pass a regexp in $bandNameRE through to a while loop, >but > >it keeps bailing complaining about an "unrecognised escpape \S", but when >I > >put the regexp directly into the condition it's happy. Why is this? > >That's because you're using a double-quoted string. Regexes are a >slightly different form of "string". If you use a string to hold a regex, >you'll need to use single quotes, or use backslashes in double quotes: > > $re = '\w+-\d+'; > # or > $re = "\\w+-\\d+"; > >You'd probably want double-quotes since you want to put a variable in the >regex. But there's another way... > > >2. The other thing is that $name could be upper or lower case. I know I >need > >to chuck \i into the regexp, which I assumed would be >(^$bandName\i)(\S)(.*) > >but quite clearly isn't. > >You can add the /i, /m, /s, and /x modifiers to a part of the regex by >using the (?i) construct: > > $re = '(this)((?i)that)'; # matches thisTHaT but not THISTHaT > >or the (?i:) construct, which does both grouping (not capturing) and sets >a modifier at the same time: > > $re = '(this)(?i:that)'; # like above > >But you want to use qr//. This creates a regex object. > > $re = qr/(^$name)(\S)(.*)/i; > >Ta da! Looks like a regex in action, kinda. And you can use it like so: > > if (/$re/) { ... } > >or > > if ($str =~ /$re/) { ... } > # or > # if ($str =~ $re) { ... } > >-- >Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ >RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ >** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** > > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]