If you aren't fussed about leading and trailing spaces, you can modify the regex thusly:
/^\s*\w{5}\s\w{4}\s*$/
</code>
Update: Yeah, I know the question was pretty explicit that he wanted to match exactly a 5 letter word followed by a 4 letter word. The question had already been answered so I posted this in case it's of use to anyone else.
It happens occasionally that you think - I want a regex to allow
x and and make it too unforgiving to allow for mistakes in user input. Correct me if I'm wrong, but I don't think the code I posted is incorrect?
Update 2: Fastolfe pointed out that I used character classes when I didn't need them so I took them out. He was quite right - not sure why I used them, but I don't think they did any harm, I originally posted:
/^[\s]*\w{5}\s\w{4}[\s]*$/
$code or die
Using perl at
The Spiders Web
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.