I ran your code, and it behaves as I would expect. If I type in "barbaz$" or "oob" and hit the
$go_button, I get a match, and if I type "foot" or "xyz", I don't get a match. Isn't this exactly what you want?
I am guessing you think the input text has to be wrapped in a
qr// for it to work, but that's not the case. You only need to feed a regular-expression
string to
m//, not a regular-expression
object (which you construct with
qr//), In fact, since
qr// is really just a chunk of perl code, you would need to
eval it to get it to work. Replacing the last line of your command sub for
$go_button with the following would force users to enter their regular expression using
qr//:
$string =~ eval $exp ? print STDOUT "match!\n" : print STDOUT "No matc
+h!\n";
It is only by chance that
(?-xism:foo) matches "foobarbaz" - it has nothing to do with the fact that this is the string representation of the regular expression
qr/foo/. The "(?-xism:" signals the start of a non-capturing grouping with the x, i, s and m modifiers turned off. This little construct is buried within
perlre. I can't say I ever realized that the stringification of a regular expression is itself another related, similar regular expression.
Update: Boy do I feel like a fool! Whenever Perl printed
(?-xism:the regex), I always read it as "Regular expression-ism: 'the regex'". As in "The United States' policy was one of protection
ism". I never realized Perl was being helpful and showing me the modifiers it was (or wasn't) using.
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.