in reply to grep - serach limited to complete word only

Thank you for all of you who reply this question. :)

One more question on the word boundary: I read the documentation and the document said,

"is a spot between two characters that has a \w on one side of it and a \W on the other side of it (in either order), counting the imaginary characters off the beginning and end of the string as matching a \W "

Can I said the word boundary is any character in class \w?(e,g, space, tab, newline?)

  • Comment on Re: grep - serach limited to complete word only

Replies are listed 'Best First'.
Re^2: grep - serach limited to complete word only
by Not_a_Number (Prior) on Mar 30, 2008 at 14:49 UTC
    Can I said the word boundary is any character in class \w?(e,g, space, tab, newline?)

    Not really, no. To illustrate the difference:

    my $string = 'run rabbit run'; print "Matched with word boundary\n" if $string =~ /\brun\b/; print "Matched with non-word char\n" if $string =~ /\Wrun\W/;

    Update: I (and the above code) assume you meant 'class \W' rather than 'class \w.' If you meant 'class \s', the answer is the same:

    print "Matched with whitespace\n" if $string =~ /\srun\s/;
Re^2: grep - serach limited to complete word only
by jwkrahn (Abbot) on Mar 30, 2008 at 15:31 UTC

    The \w character class does not include space, tab or newline.   The \w character class is comprised of letters, numbers and '_' the underscore character.

    Also, the \b word boundary does not match a character, it is a zero-width assertion, it matches between characters.