Well, first you have to know that a RE evaluates not
on a character but
between characters. Take the following RE:
/hello/
What actually happens is that the RE engine starts first not directly at the 'h' but at the invisible area just
before it. Then when it finds an 'h' in your string, the RE then jumps
between the 'h' and the 'e' and starts looking for an 'e'. So by now you should be imagining your RE as a sting of characters with invisible spaces in between them that the RE engine sits at while looking for the next character.
When the RE engine encounters the \b metacharacter, it tells the engine to look not only look at the character after the invisible spaces but also at the character before the invisible space. The engine then compares the two characters to eachother and asks a question: "Is the character to the left of me a non-word character (that is anything except a number, a letter, or an underscore), and is the character to the right of me a word character?" If this is the case, then the RE will find a match because it recognizes this invisible space as a "word boundary" and that it is between a non-word character and a word character. Note that this is also true at the end of a word except that it has a word character to the left and a non-word character to the right.
Hope this helps. Let me know if you have specific questions.
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot";
$nysus = $PM . $MCF;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.