Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Extract sequence of UC words?

by amarquis (Curate)
on Aug 18, 2008 at 13:56 UTC ( #704933=note: print w/replies, xml ) Need Help??

in reply to Extract sequence of UC words?

It grabs only one word because you are matching for a sequence of upper case letters only. To have it match 'TEST SENTENCE' you'll have to have it match upper case letters OR spaces.

But wait! The regex will then actually match ' TEST SENTENCE ' (including the space before and after the capitalized sequence). So what you really need is to make a match of:

  1. One upper case letter
  2. Any number of upper case letters/spaces
  3. One upper case letter

The requirement to match a beginning and ending upper case letter will also make it not match just the 'F' of 'Foo'.

Edit: gaal is smarter than I, heh.

Replies are listed 'Best First'.
Re^2: Extract sequence of UC words?
by Anonymous Monk on Aug 18, 2008 at 14:04 UTC
    Thanks, I modified it like so:
      | and + inside a character class aren't special, they're just regular characters, so your regex would match "FO O|B+++A R". /[A-Z ]+/ (which is what I think you probably meant) won't work either.

      Bonus points will be given if you tell us why!

      Update: BrowserUK has already seen what was missing. You missed out AnonyMonk

      Note that the regex expression  [A-Z\|\s+] defines a set of characters that includes the '|' ('pipe') character. Within a character set, the pipe has no special meaning; i.e., it is not the regex alternation metacharacter.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://704933]
[choroba]: When working at a bank, we had a colleague who entered mining early enough to have lots of bitcoins. He used to say "I go to work just because I'm too bored at home."
[Corion]: choroba: Aah, no, I do it because of the money :)
[choroba]: And when asked "How are you?" in the morning, his reply was usually "I don't know, haven't checked the bitcoin rates yet."
[Corion]: Heh - if I defined myself through the money I make, I would now only be 80% myself :-D
[choroba]: :-D
LanX emacs is the oldest textadventure ...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2017-09-21 15:32 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (249 votes). Check out past polls.