Scott E Robinson <[EMAIL PROTECTED]> wrote: > > [...] I wonder if there's an easy way to keep the following > regular expression from matching if the string in the regex > is null: > > $_ = ":B000:L520:M260:M:88:8:M602:"; > $string_to_match="whatever"; > $count = () = /\b($string_to_match)\b/g; > > If $string_to_match is null, whatever's in $_ matches it -- and > for some reason i don't understand it matches twice for every > colon-delimited piece of $_, though that hardly matters.
Since \b and the empty parens are both zero-width, the expression will match the beginning and end of each "word". Put another way, these are all more or less equivalent /\b/ /\b()\b/ /\b\b\b\b\b\b/ > Is there an easy way to keep the null string from matching > anything? It would have saved me an evening if I'd known > about it. Easier to test $string_to_match before using it in the regex. if ($string_to_match) { $count = ... } -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]