davido's (almost) exhaustive answer ++ should give you plenty to chew on... for this and many other regex issues.

But I read your goal a bit differently -- based on your apparent failure to fully understand code tags (your last line needs them around abc10 to make it read as something other than a link). Since it is a link, I'm going to work on the assumption you really meant what you said, above, abc10.

... and davido's answer covers that... but if you want your regex to match a line which contains exactly abc10 and nothing else, then you have this additional option:

See below.  =~ /^abc10/$ (where "$" is another way to send EOL)
On another hand, if you'd like to match abc10, abc01 and abc11, you can use a character class (that's what a set of chars/digits inside square brackets is called):
#!/usr/bin/perl use 5.014; my @ar=('abc10', 'abc11', 'abc01', 'abc02', 'abc111'); for $_( @ar ) { if( $_ =~ /^abc[10]{2}/Z/ ) # wrong; see below { say $_; } }
where the "^" is another way to say, 'match at the start of the string' and the curly-wrapped "2" is a quantifier -- match a 1 or a 0 and do so exactly 2 times.

This little script spits out:

983013.pl abc10 abc11 abc01

Update: Two bad screwups in one post. Thanks to AnomalousMonk for msg'ing me about them.

First code sample should have the EOL marker, $, inside the regex-terminating "/". My bad!

Second snippet, line seven, should be \Z as it was in the code I actually tested... after posting the inaccurate version. i.e., if( $_ =~ /^abc[10]{2}\Z/ )

Apologies to any who tried to use the advice.


In reply to Re: problem with regex by ww
in thread problem with regex 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.