Yes, I noticed the error in my description of \b after having posted, and despite recent discussions, the ability for laypeople to edit parent nodes still doesn't exist. It would have been more accurate for me to say that \b doesn't care about whether it's being used at the beginning of a word or at the end of a word. And my point was, why should (?=...) care whether it's being used at the beginning or the end of the text it anchors its assertion to.

You are accurate that \b looks at both sides. I think that merlyn provided the perfect clarification; \b has alternation built into it. It either looks like (?<=\W)(?=\w) or like (?<=\w)(?=\W) depending on whether it's being used at the beginning or the end of a word.

So \b is not a simple lookahead or lookbehind assertion, it is a complex lookbehind/ahead in alternation with an opposing lookbehind/ahead.

Similar assertions could be custom written too. Say for example I wanted to create \x (my new metacharacter that means boundry between space and nonspace). Well, I can't name it \x, but I suppose I could name it $x. But whatever I call it, the definition would be: (?:(?<=\s)(?=\S))|(?:(?<=\S)(?=\s))

As far as what direction (?=...) looks, I didn't really want it to look both ways at once. I just thought it a little confusing that it could only look ahead. Without the prior benefit of merlyn's reply, thus not fully understanding the \b example, it seemed odd that (?=...) should be incapable of being used for lookbehind just as easily as lookahead. I understand that distinction now.

As for my other comment regarding the fact that (?<=...) must be fixed-width, I understand that as liz stated, it would be a backtracking nightmare if such were not the case, but still don't fully understand why that is so. I'll have to re-read the section in the Owls book about DFA engines and backtracking. Eventually it will sink in. ;)


Dave


"If I had my life to do over again, I'd be a plumber." -- Albert Einstein

In reply to Re: Re: Why do zero width assertions care about lookahead/behind? by davido
in thread Why do zero width assertions care about lookahead/behind? by davido

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.