Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Pattern for a single wordby sundialsvc4 (Abbot) |
on Jun 19, 2017 at 22:35 UTC ( [id://1193113]=note: print w/replies, xml ) | Need Help?? |
Unfortunately, no one has yet invented a computer which can “guess” what you mean. But nevertheless, regular-expressions do give you a lot options without obliging you to write any source-code. For example, one possible variation would be this: /he.*super.*\_([a-z]+)$/i This particular regular-expression, for instance, looks for "he" followed by "super", so-far not caring where in the string these substrings occur nor what (if anything) surrounds them, so long as they do occur in that sequence. But then, it does start to care: it next wants to find an underscore followed by “one or more letters,” occurring at the end of the string. The parentheses indicate that it wants to extract that group of letters, so that you can later retrieve what it has extracted for you. Furthermore, the /i modifier tells us that the regex does not care about upper vs. lower-case characters, throughout. Is this the “right answer” for your problem? Only y-o-u can know! However, if you will re-state your actual requirement more clearly and more fully, plenty of folks around here are happy to continue to help you.
In Section
Seekers of Perl Wisdom
|
|