sandyago has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Word boundaries
by GrandFather (Saint) on Jan 04, 2016 at 07:11 UTC

    You already asked that question and got a good answer from kennethk at Re: Word boundaries. If you didn't understand the reply you should post a follow up question there.

    Premature optimization is the root of all job security
Re: Word boundaries
by 1nickt (Canon) on Jan 04, 2016 at 07:18 UTC

    Hello, sandyago.

    In regular expression syntax many flags are paired upper- and lower-case letters, one signifying the opposite of the other.

    In this case \b matches a boundary between a word character and a non-word character, while \B matches anything else.

    $ perl -E' for ("cat","a dog") { say if /\ba/; } '
    a dog
    $ perl -E' for ("cat","a dog") { say if /\Ba/; } '
    cat
    See perlretut for an introduction to regular expressions.

    The way forward always starts with a minimal test.
Re: Word boundaries
by kcott (Archbishop) on Jan 04, 2016 at 07:24 UTC

    G'day sandyago,

    Very briefly, \b matches a word boundary and \B matches NOT a word boundary.

    Read "perlrebackslash - Perl Regular Expression Backslash Sequences and Escapes". In particular, the Assertions section of that documentation has a fairly in-depth discussion as well as examples.

    Finally, there's quite a few examples of the upper- and lower-case versions having an opposite meaning. For example, \d matches a digit and \D matches NOT a digit; similarly for \s and \S, \w and \W and so on.

    — Ken