pcre example to match an empty line

Discussion in 'C Programming' started by Ram Prasad, Apr 14, 2011.

  1. Ram  Prasad

    Ram Prasad Guest

    I have a script to match for the first blank line in the file

    I am trying to use a pcre pattern like '^\s*$' but this doesnt work
    Can someone please find where the code is wrong

    The code is here
    http://pastebin.com/Xap9dUWt
    Ram Prasad, Apr 14, 2011
    #1
    1. Advertising

  2. Ram  Prasad

    Seebs Guest

    On 2011-04-14, Ram Prasad <> wrote:
    > I have a script to match for the first blank line in the file


    A "script"?

    > I am trying to use a pcre pattern like '^\s*$' but this doesnt work
    > Can someone please find where the code is wrong


    This question does not visibly have anything to do with the C language.

    Please read this:

    http://www.catb.org/~esr/faqs/smart-questions.html

    Then, once you've thought that through, try asking your question intelligibly
    and in the appropriate place, which is very unlikely to be comp.lang.c.

    -s
    --
    Copyright 2011, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
    Seebs, Apr 14, 2011
    #2
    1. Advertising

  3. Ram Prasad <> writes:

    > I have a script to match for the first blank line in the file
    >
    > I am trying to use a pcre pattern like '^\s*$' but this doesnt work
    > Can someone please find where the code is wrong
    >
    > The code is here
    > http://pastebin.com/Xap9dUWt


    The problem is not a C one, but since I can't suggest the right group to
    ask libpcre questions in, I'll venture an answer.

    You clip the newline off the string (by the way, you should check that
    the last character of the string really is a newline) but you don't tell
    pcre_exec that the string is now one character shorter. I.e. you must
    pass n-1 not n to pcre_exec.

    --
    Ben.
    Ben Bacarisse, Apr 14, 2011
    #3
    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. Victor
    Replies:
    2
    Views:
    629
    Victor
    May 17, 2004
  2. news

    can you help a new pcre user???

    news, Jul 1, 2004, in forum: C Programming
    Replies:
    3
    Views:
    290
  3. pcre.c : And Operator

    , Feb 17, 2005, in forum: C Programming
    Replies:
    17
    Views:
    1,008
    Gregory Toomey
    Feb 19, 2005
  4. mainland

    about pcre regex lib

    mainland, Jul 11, 2006, in forum: C Programming
    Replies:
    16
    Views:
    2,225
    Kenny McCormack
    Jul 22, 2006
  5. Bernd Muent
    Replies:
    2
    Views:
    504
    Bernd Muent
    Feb 15, 2006
Loading...

Share This Page