Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
I am in the process of brushing up on my perl basics, reviewing Learning Perl, etc.

I am have a little question dealing with Regex anchoring patterns.

my $string = 'silent eleven'; if ($string =~ /\b \b/){ print "yes to 1\n"; } if ($string =~ /\b \b$/){ print "yes to 2\n"; } if ($string =~ /\b$/){ print "yes to 3\n"; }
Z:\>perl yes to 1 yes to 3
Why is the second if statement not returning true? Can these 2 "anchors" not be next to each other? Perhaps I am missing the point of using anchors. Any help or explanation would be appreciated.

Spread Firefox

In reply to Regex Anchors confusion by silent11

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.