http://www.perlmonks.org?node_id=705001


in reply to Re^4: Extract sequence of UC words?
in thread Extract sequence of UC words?

The issue I have with your examples, BrowserUk, is that you are mandating at least 2 upper case letters. My regexp permits a single capital letter.

I think it is important to have the optional section, because the desired expression is "one or more upper case letters" optionally followed by any number of "spaces followed by upper case letters".

Replies are listed 'Best First'.
Re^6: Extract sequence of UC words?
by BrowserUk (Patriarch) on Aug 19, 2008 at 06:31 UTC

    I upvoted your post above, but still your regex m/(\b(?:[A-Z]+(?:\s+[A-Z]+)*)+\b)/g made me squirm. Whenever I see sequences of nested quantifiers like that:+)*)+ I get uncomfortable, remembering various pathelogical cases I've constructed in the past.

    To that end, I thunk again, and came up with this which I believe meets the 'spec', whilst avoiding the nested quantifiers;

    m[ ( \b [A-Z] (?: [A-Z\s]* [A-Z] )? \b ) ]gx

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.