Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Why doesn't quantifier work with character classes?

by BrowserUk (Pope)
on Aug 13, 2012 at 22:21 UTC ( #987228=note: print w/ replies, xml ) Need Help??


in reply to Why doesn't quantifier work with character classes?

I thought {8} will match exactly 8 characters, but looks like I am wrong!

You aren't wrong, it does match exactly 8 characters ... but if those 8 characters are at the start of a line containing more than 8 characters, it still matches exactly the first 8.

You need to anchor your regex: Ie. /^[ATGC]{8}$/. Now it will only match lines that contain exactly 8 characters.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?


Comment on Re: Why doesn't quantifier work with character classes?
Download Code
Re^2: Why doesn't quantifier work with character classes?
by thezip (Vicar) on Aug 13, 2012 at 22:30 UTC

    Please correct me if I am wrong (or if I misunderstood your statement), but there is nothing in OP's regex that restricts a match to the beginning of a line. Hence, the eight consecutive characters may appear anywhere on a line. Right?


    What can be asserted without proof can be dismissed without proof. - Christopher Hitchens, 1949-2011

      Correct!
      "BrowserUk" and "thezip" 's suggestions solved the problem. Thanks.

      Hence, the eight consecutive characters may appear anywhere on a line. Right?

      Yes, but since the lines that match the character class in question contain only those characters; and a regex will always match as early as possible; that'll be at the beginning of the line in these cases.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://987228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-12-20 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (94 votes), past polls