Loading ...
Sorry, an error occurred while loading the content.
 

Re: Regexp help

Expand Messages
  • Erik Christiansen
    ... Wot ... just trust the problem specification? OK, the OP might be a mathematician or engineer, since fortran is mentioned, so you re probably right. But in
    Message 1 of 15 , Jul 30, 2013
      On 30.07.13 07:41, Ben Fritz wrote:
      > The OP specifically said that valid decimals are "in the form 1.0D0,
      > or more precisely \d\+\.\d\+D\d\+" so I didn't try stuff like "123."
      > or ".123".

      Wot ... just trust the problem specification? OK, the OP might be a
      mathematician or engineer, since fortran is mentioned, so you're
      probably right. But in years gone by, I sometimes wrote regexes for
      others in a technical department, and the original problem spec almost
      always had to be tightened, to exclude stuff which hadn't been thought of.

      > But possibly as in the other thread we need to account for negative numbers?

      If we change the test text to:

      123 123.0 123. -456 0.123 .123 789

      then what we had:

      > > /\v\.@<!<\d+>\.@!

      also finds -456, but the cursor is on the 4, not the minus sign.
      If signed integers are also needed, we'd probably have to ditch the
      precondition, since /\v(-?|\.@<!)<\d+>\.@! introduces an ambiguity which
      defeats that alternative. (It's rotten regex construction.)

      This, though, finds "-456", rather than "456":

      \v(^|[ \t+-])<\d+>\.@!

      but again finds "123" " 789", as before. Maybe that's OK?

      Erik

      --
      Remembering is for those who have forgotten.
      - Chinese proverb

      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Nikolay Pavlov
      On Jul 30, 2013 7:26 PM, Erik Christiansen ... numbers? ... If you are speaking about numbers in programming language you should
      Message 2 of 15 , Jul 30, 2013


        On Jul 30, 2013 7:26 PM, "Erik Christiansen" <dvalin@...> wrote:
        >
        > On 30.07.13 07:41, Ben Fritz wrote:
        > > The OP specifically said that valid decimals are "in the form 1.0D0,
        > > or more precisely \d\+\.\d\+D\d\+" so I didn't try stuff like "123."
        > > or ".123".
        >
        > Wot ... just trust the problem specification? OK, the OP might be a
        > mathematician or engineer, since fortran is mentioned, so you're
        > probably right. But in years gone by, I sometimes wrote regexes for
        > others in a technical department, and the original problem spec almost
        > always had to be tightened, to exclude stuff which hadn't been thought of.
        >
        > > But possibly as in the other thread we need to account for negative numbers?
        >
        > If we change the test text to:
        >
        > 123 123.0 123. -456 0.123 .123 789
        >
        > then what we had:
        >
        > > > /\v\.@<!<\d+>\.@!
        >
        > also finds -456, but the cursor is on the 4, not the minus sign.
        > If signed integers are also needed, we'd probably have to ditch the
        > precondition, since /\v(-?|\.@<!)<\d+>\.@! introduces an ambiguity which
        > defeats that alternative. (It's rotten regex construction.)
        >
        > This, though, finds "-456", rather than "456":
        >
        > \v(^|[ \t+-])<\d+>\.@!
        >
        > but again finds "123" " 789", as before. Maybe that's OK?

        If you are speaking about numbers in programming language you should take care about expressions: there is no number -456 in expression 123-456. Also note that in programming languages negative numbers may exist only as optimization for minus being an unary operator in an expression -456 (it does not make any difference whether you treat -456 as unary minus applied to positive 456 or as a negative number; but the latter is faster). So I would not widen the request this way.

        \v[[:alnum:].]@<!\d+[[:alnum:].]@!

        should be fine.

        > Erik
        >
        > --
        > Remembering is for those who have forgotten.
        >                             - Chinese proverb
        >
        > --
        > --
        > You received this message from the "vim_use" maillist.
        > Do not top-post! Type your reply below the text you are replying to.
        > For more information, visit http://www.vim.org/maillist.php
        >
        > ---
        > You received this message because you are subscribed to the Google Groups "vim_use" group.
        > To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        > For more options, visit https://groups.google.com/groups/opt_out.
        >
        >

        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
         
        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
         
         
      Your message has been successfully submitted and would be delivered to recipients shortly.