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

interpolating in regex

Expand Messages
  • Thierry Flauss
    Hi all, I tried without success to interpolate a variable in a regex in a vimscript; let x = 3 echo matchstr( abcdef , . { .eval( x ). } ) I was expecting the
    Message 1 of 3 , Oct 12, 2011
    • 0 Attachment
      Hi all,

      I tried without success to interpolate a variable in a regex in a vimscript;

      let x = 3 
      echo matchstr("abcdef", '.\{'.eval("x").'}')

      I was expecting the string "abc" as a result but got a no match.

      How could this be done?

      Thank you for your help.


      ThF

      --
      You received this message from the "vim_mac" 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
    • Thierry Flauss
      Solved ! By using a register. let x = 3 let @a = . { .eval( x ). } echo matchstr( abcdef , @a) displays abc However, I wonder if a solution exists that
      Message 2 of 3 , Oct 12, 2011
      • 0 Attachment
        Solved !

        By using a register.

          let x = 3
          let @a = '.\{'.eval("x").'}'
          echo matchstr("abcdef", @a) displays "abc"

        However, I wonder if a solution exists that doesn't require the use of a register.


        ThF


        On Wed, Oct 12, 2011 at 12:04, Thierry Flauss <thfjunior@...> wrote:
        Hi all,

        I tried without success to interpolate a variable in a regex in a vimscript;

        let x = 3 
        echo matchstr("abcdef", '.\{'.eval("x").'}')

        I was expecting the string "abc" as a result but got a no match.

        How could this be done?

        Thank you for your help.


        ThF

        --
        You received this message from the "vim_mac" 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
      • Thierry Flauss
        I feel ashamed of not having seen the obvious solution: let x = 3 echo matchstr( abcdef , . { .x. } ) *ThF* ... -- You received this message from the
        Message 3 of 3 , Oct 12, 2011
        • 0 Attachment
          I feel ashamed of not having seen the obvious solution:

             let x = 3
             echo matchstr("abcdef", '.\{'.x.'}')



          ThF


          On Wed, Oct 12, 2011 at 17:03, Thierry Flauss <thfjunior@...> wrote:
          Solved !

          By using a register.

            let x = 3
            let @a = '.\{'.eval("x").'}'
            echo matchstr("abcdef", @a) displays "abc"

          However, I wonder if a solution exists that doesn't require the use of a register.


          ThF



          On Wed, Oct 12, 2011 at 12:04, Thierry Flauss <thfjunior@...> wrote:
          Hi all,

          I tried without success to interpolate a variable in a regex in a vimscript;

          let x = 3 
          echo matchstr("abcdef", '.\{'.eval("x").'}')

          I was expecting the string "abc" as a result but got a no match.

          How could this be done?

          Thank you for your help.


          ThF


          --
          You received this message from the "vim_mac" 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
        Your message has been successfully submitted and would be delivered to recipients shortly.