negative lookbehind and \.

Discussion in 'Perl Misc' started by Isaac Councill, Jan 10, 2004.

  1. Hello,

    I am trying to extract capitalized words from text that are not the
    first words in a sentence. I thought it would be straightforward
    using negative lookbehind for periods:

    m/((?:(?<!\. )|(?<!\. ))[A-Z][a-z]+)/g

    but not the case.

    The above regexp will match all capitalized words not preceded by one
    or two spaces. For instance, if I use a lookbehind with \. followed
    by one space, I get no results unless there are capitalized words not
    preceded by a space (e.g. "(Something" - I can extract "Something").
    It seems that the matcher is simply ignoring the "\.". What am I
    missing here?

    Thanks,
    Isaac
     
    Isaac Councill, Jan 10, 2004
    #1
    1. Advertising

  2. Isaac Councill () wrote:
    : Hello,

    : I am trying to extract capitalized words from text that are not the
    : first words in a sentence. I thought it would be straightforward
    : using negative lookbehind for periods:

    : m/((?:(?<!\. )|(?<!\. ))[A-Z][a-z]+)/g

    : but not the case.

    : The above regexp will match all capitalized words not preceded by one
    : or two spaces.

    I don't think so. I think the double negative has confused you.

    E.g.

    `one space. Word'

    (?<!\. ) is false but (?<!\. ) is true, therefore the | is true,
    therefore Word will be matched.

    `two spaces. Word'

    (?<!\. ) is now true even though (?<!\. ) is false, therefore once again
    the | is true, therefore Word is matched.
     
    Malcolm Dew-Jones, Jan 10, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas F. O'Connell

    Negative Lookbehind and Wildcards

    Thomas F. O'Connell, Feb 27, 2004, in forum: Perl
    Replies:
    1
    Views:
    732
    Gunnar Hjalmarsson
    Feb 28, 2004
  2. mail
    Replies:
    1
    Views:
    539
    Will Stranathan
    Mar 2, 2004
  3. Replies:
    2
    Views:
    561
  4. Isaac Councill

    negative lookbehind and \. [ADDENDUM]

    Isaac Councill, Jan 10, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    105
    Isaac Councill
    Jan 10, 2004
  5. Peng Yu

    Negative Lookbehind and Wildcards

    Peng Yu, Jun 13, 2010, in forum: Perl Misc
    Replies:
    3
    Views:
    250
    C.DeRykus
    Jun 14, 2010
Loading...

Share This Page