in reply to Re: regexp pattern match help?
in thread regexp pattern match help?

\B and \b are zero-width assertions, and therefore, they don't make any sense inside a character class. Hence, [^\B#] doesn't do what you think:
$ perl -Dr -ce '/[^\B#]/' Compiling REx `[^\B#]' size 12 Got 100 bytes for offset annotations. first at 1 1: ANYOF[\0-"$-AC-\377{unicode_all}](12) 12: END(0) stclass `ANYOF[\0-"$-AC-\377{unicode_all}]' minlen 1 Offsets: [12] 1[6] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 7[0] Omitting $` $& $' support. EXECUTING... -e syntax OK Freeing REx: `"[^\\B#]"' $
Which means that [^\B#] matches any character that is not a B nor a #.

Abigail

Replies are listed 'Best First'.
Re: Re: regexp pattern match help?
by Elijah (Hermit) on Dec 03, 2003 at 06:52 UTC
    Ok cool, good to know. I think I have a decent way of accomplishing this but need a good way to set the length of string to be colored to the whole commented string. Here is what I have so far:
    my $word = '#'; my $next = "1.0"; while (my $from = $t->search(-regexp, "\\B$word\\B", $next +, "end")) { my @comment = split(/#/, $_); #print "\$comment[0] equals ",$comment[0],"\n"; #print "\$comment[1] equals ",$comment[1],"\n"; if ($comment[1]) { my $word_len = length $comment[1] + length $word; }else{ my $word_len = length $comment[0] + length $word; } print $word; print $word_len; $next = "$from + $word_len chars"; $t->tagAdd("orange", $from, $next); $t->tagAdd("bold", $from, $next); }
    I decided to use split to accomplish what I wanted but for some reason on each string the length only ends up being 5 so the first 5 characters of the commented strings gets colored. How can I color the whole comment once the comment character is found. Oh and am I searching for the comment symbol the best way using the "B"?
      You have two problems there.

      The my $word_len's you declare inside the if statement are not visible outside the if statement, so you are seeing some other $word_len, either a global variable or a lexical in an outer scope.

      And you have a precedence problem. You are doing like length($comment[1] + length $word); make it like length($comment[1]) + length $word instead.