Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Pattern for a single word

by sundialsvc4 (Abbot)
on Jun 19, 2017 at 22:35 UTC ( [id://1193113]=note: print w/replies, xml ) Need Help??


in reply to Pattern for a single word

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 05:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found