use YAPE::Regex::Explain; print YAPE::Regex::Explain->new("A\\B")->explain; __END__ The regular expression: (?-imsx:A\B) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- A 'A' ---------------------------------------------------------------------- \B the boundary between two word chars (\w) or two non-word chars (\W) ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
use YAPE::Regex::Explain; print YAPE::Regex::Explain->new("\\B")->explain; __END__ The regular expression: (?-imsx:\B) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- \B the boundary between two word chars (\w) or two non-word chars (\W) ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
use re 'debug'; $x = "A\\B"; $y = "Here is A\\B"; print $y =~ /$x/ ? "y" : "n"; __END__ Compiling REx `A\B' size 4 Got 36 bytes for offset annotations. first at 1 1: EXACT <A>(3) 3: NBOUND(4) 4: END(0) anchored "A" at 0 (checking anchored) minlen 1 Offsets: [4] 1[1] 0[0] 2[2] 4[0] Guessing start of match, REx "A\B" against "Here is A\B"... Found anchored substr "A" at offset 8... Starting position does not contradict /^/m... Guessed: match at offset 8 Matching REx "A\B" against "A\B" Setting an EVAL scope, savestack=3 8 <Here is > <A\B> | 1: EXACT <A> 9 <Here is A> <\B> | 3: NBOUND failed... Match failed nFreeing REx: `"A\\B"'
use re 'debug'; $x = "\\B"; $y = "Here is \\B"; print $y =~ /$x/ ? "y" : "n"; __END__ Compiling REx `\B' size 2 Got 20 bytes for offset annotations. first at 1 1: NBOUND(2) 2: END(0) stclass "NBOUND" minlen 0 Offsets: [2] 1[2] 3[0] Matching REx "\B" against "Here is \B" Matching stclass "NBOUND" against "Here is \B" Setting an EVAL scope, savestack=3 1 <H> <ere is \B> | 1: NBOUND 1 <H> <ere is \B> | 2: END Match successful! yFreeing REx: `"\\B"'

In reply to Re: Strange backslash in regexp behaviour by Anonymous Monk
in thread Strange backslash in regexp behaviour by Anonymous Monk

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.