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 ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]