Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How do I reverse the order of the first and last word of a string?

by jonadab (Parson)
on Mar 11, 2007 at 16:44 UTC ( #604238=note: print w/ replies, xml ) Need Help??


in reply to Re^6: How do I reverse the order of the first and last word of a string?
in thread How do I reverse the order of the first and last word of a string?

What exactly is the role of the ^

In a character class (the square brackets thing), if you put ^ (called a "caret") first before any characters, it negates the whole class, so it means "any character _except_ one of these". (You can include a caret in a character class and have it just be a literal ^ character, if it's not the first thing; it only has this special negate-the-class meaning if it's first.)

This is all only in a character class, though. In other regular-expression contexts, the caret is a zero-width positive assertion that matches only at the beginning. (Whether it matches at the beginning of the line or the beginning of the string depends on the options you're using.)

So this regular expression matches any string that starts with a vowel:

/^[aeiou]/i

But this one matches any string that starts with something *other* than a vowel:

/^[^aeiou]/i

(Technically, I should say "unaccented Latin-alphabet vowel" in both of those statements, but if you assume strings are composed of printed ASCII characters then what I said is good enough. The extra verbiage would only be necessary to accommodate other character sets, notably Unicode. And anyway, the meaning of the word "vowel" is really not the main point here.)

-- 
We're working on a six-year set of freely redistributable Vacation Bible School materials.


Comment on Re: How do I reverse the order of the first and last word of a string?
Select or Download Code
Re^2: How do I reverse the order of the first and last word of a string?
by jeanluca (Deacon) on Mar 11, 2007 at 17:05 UTC
    I already thought something strange was going on with the caret. Thanks!

    LuCa

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (13)
As of 2014-07-24 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (160 votes), past polls